开发者

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

开发者 https://www.devze.com 2022-12-19 06:32 出处:网络
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.Cl

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

精彩评论

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

关注公众号