Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
484 views
in Technique[技术] by (71.8m points)

c# - 如何仅在DateTime对象中的C#中删除日期的时间部分?(How to remove time portion of date in C# in DateTime object only?)

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 .

(我需要删除日期时间的时间部分,或者以object形式(而不是string形式)以以下格式显示日期。)

06/26/2009 00:00:00:000

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

(我无法使用任何string转换方法,因为我需要object形式的日期。)

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.

(我尝试首先将DateTime转换为string ,从中删除特定于时间的日期,但是一旦我再次将其转换回DateTime object ,它将立即添加12:00:00 AM 。)

  ask by im useless translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use the Date property:

(使用日期属性:)

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

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...