如何仅在DateTime对象中删除C#中的日期时间部分? [英] How to remove time portion of date in C# in DateTime object only?
本文介绍了如何仅在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
.
这篇关于如何仅在DateTime对象中删除C#中的日期时间部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文