I’m sure this is very easy, but I’ve got a sudden mental block.
I’m trying to get a DateTime object for the next occurence of 3am. For example, if DateTime.Now is 16/july/2009 : 12:04pm – the next occurance of 3am would be 17/july/2009 : 03:00
However, if DateTime.Now was 17/july/2009 : 01:00 then the next occurence would still be 17/july/2009 : 03:00 (not the day after).
Does that make sense?
One option:
Another:
Lots of ways of skinning that particular cat 🙂
This is all in local time of course, which means you don’t need to worry about time zones. Life becomes trickier if you want to get time zones involved…
Note that it’s a good idea to take
DateTime.Nowonce to avoid problems if the date rolls over while you’re calculating…