Easiest way to get an NSDate representation of "the next 7am that will occur" in Cocoa?
- by Drarok
I figure I can achieve what I want by using NSCalendar and NSDateComponents, but that would run something like the following:
Get "now"
Create an NSDateComponents from "now".
If "now" is pre-7am, then use today's date.
If "now" is post-7am, use tomorrow's date.
If today is the last day of the month, increase month, set day to 1.
If it was December, increase year by 1 also.
Set hour, minute, second.
Create a new NSDate.
It all seems very long-winded, but that appears to be what other answers on here suggest, and the documentation doesn't offer any clues. I'm going back and forth between all the date and calendar classes I can find.
Is there a simple way to ask for the "next occurring 7am" ?
Thanks.