How would I be able to determine if a certain NSDate object falls within a certain day? Since all dates calculate to the GMT time zone, a date maybe actually be on the 8th instead of the 9th, for example. What’s the best way to account for the time zone difference when calculating things like days, months, day of week, etc.
Share
An
NSDateis an absolute point in time. When you want to know which day it falls on, you have to consider your specific time zone. Since you get theNSDateComponentswith anNSCalendar, you can usesetTimeZone:on the calendar to get the components (month, day, hour etc.) for the time zone you’re interested in.If you deal with “calendar dates” (i.e. dates that should always represent a specific day/month and not an absolute point in time), you could always use a fixed time zone (e.g. GMT) to present the dates.
NSDateFormatter(which you use for displaying dates to the user) also has atimeZoneproperty.