开发者

How to create a DateTime nicely which is today at 23:00

I want a DateTime variable which is today (any given time of the day) at 23:00.

There has simply got to be a cleaner way to do this开发者_JAVA百科 because this reminds me too much of good ol' ASP.Classic...

var startDate = DateTime.Parse(DateTime.Now.ToShortDateString() + " 23:00:00");

Anyone?


var eleven = DateTime.Today.AddHours(23);


var elevenPM = DateTime.Today.AddHours(23);


var dt = DateTime.Now.Date + TimeSpan.FromHours(23);


A clean Way is:

DateTime myTime = DateTime.Now.Date.AddHours(23); 

Another Way is:

DateTime myTime = DateTime.Now.Date + new TimeSpan("23","0","0");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜