如何仅在DateTime对象中删除C#中的日期时间部分?

问题描述:

我需要删除日期时间的时间部分,或者可能在对象中以 string

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

我不能使用任何字符串转换方法,因为我需要在 object form。

I can not use any string conversion methods as I need the date in object form.

我尝试首先将 DateTime 转换为 string ,从中删除时间具体的日期,但一旦我转换,它会添加 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.

使用 Date 属性:

var dateAndTime = DateTime.Now;
var date = dateAndTime.Date;

date 变量将包含日期,时间部分将为 00:00:00

The date variable will contain the date, the time part will be 00:00:00.