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");
精彩评论