如何在日期时间中仅存储日期

问题描述:

嗨!
我仅在将字符串转换为日期时遇到问题.
我从数据库获取日期作为字符串

例如:

Hi!
I have a problem in converting the string only to date.
I am getting the date as string from database

ex:

string datestring = "12/10/2012"
Datetime dt = Convert.ToDateTime(datestring);



如何将日期字段中的字符串保存为日期,因为前面的示例将日期和时间存储在一起,而我不希望时间为00:00:00.

你能帮我吗?


问候,

S. Keshaavan



How to save the string in date field as date, because the previous example is storing the date with time and I don''t want the time 00:00:00.

Can you help me please?


Regards,

S. Keshaavan

如果您不想使用DateTime的时间部分,那就不要.
首先在这里阅读: String.Format [标准日期和时间格式字符串 [自定义日期和时间格式字符串 [
If you don''t want to use the time part of DateTime then just don''t.
First read here: String.Format[^]
then go after this: Standard Date and Time Format Strings[^]
after that have some of this: Custom Date and Time Format Strings[^]

Regards,

Manfred


dateTime值就是日期和时间,如果未提供时间,则默认使用00:00:00.

您可以只使用dt对象的日期部分(我认为是dt.date),也可以将返回字符串存储为与datetime不同的类型,例如字符串.
A dateTime value is just that a Date & Time, if no time is supplied then the 00:00:00 are used by default.

You can either just use the date part of your dt object (dt.date I think)or store your return string as a different type to datetime, such as string.


只需忽略尾部由于.net框架中当前没有合适的类型,因此可以定义一个新类来实现所需的功能.
Just ignore the tail of the DateTime, because there is no current appropriate type in .net framework, of cause you can define a new class to implement the function you wanted.