If you already have a DateTime
object created and want to replace the time with the 11:59:59PM for that given date, then you can use the .Date
property to get the date with time set to 00:00:00 and then add the hours, minutes and seconds. For example:
var dt = yourDateInstance.Date.AddHours(23).AddMinutes(59).AddSeconds(59);
If by latest time, you mean 11:59:59 PM, then this should also work:
var dt = new DateTime(Now.Year, Now.Month, Now.Day, 23, 59, 59);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…