How can I set certain DateTime
value to tomorrow 9:00 AM
For example:
DateTime startTime = new DateTime.Now.AddDays(1).//setTime to 9:00 AM
Is there some SetDateTime value functionality that I don't know?
You can use two methods
DateTime.Today.AddDays(1).AddHours(9)
You can use this DateTime
constructor like;
DateTime tomorrow = new DateTime(DateTime.Now.Year,
DateTime.Now.Month,
DateTime.Now.Day + 1,
9,
0,
0);
Console.WriteLine(tomorrow);
Output will be;
18.03.2014 09:00:00
As CompuChip mentioned, this throws exception if the current day is the last day of the month.
Better you can use DateTime.Today
property with AddDays(1)
and AddHours(9)
because it get's to midnight of the current day. Like;
DateTime tomorrow = DateTime.Today.AddDays(1).AddHours(9);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With