如何删除日期的时间部分在C#中只DateTime对象?
问题描述:
我需要删除的日期时间时部分或可能具有的日期不是在字符串的形式在
对象
表格格式如下code>。
I need to remove time portion of date time or probably have the date in following format in object
form not in the form of string
.
06/26/2009 00:00:00:000
因为我需要在日期我不能使用任何字符串
转换方法对象
的形式。
我第一次尝试转换的DateTime
到字符串
,从中取出时的具体日期,但它增加了 12:00:00 AM
当我将其转换回的DateTime
对象
回来了。
I tried first converting the DateTime
to a string
, remove the time specific date from it, but it adds 12:00:00 AM
as soon as I convert it back to DateTime
object
back again.
请帮忙。
答
使用日期属性:
var dateAndTime = DateTime.Now;
var date = dateAndTime.Date;
的日期
变量将包含日期,时间部分将是 00:00:00
。
The date
variable will contain the date, the time part will be 00:00:00
.