Using NSDate is tricky to me. I know it represents a specific point in time, not tied to a specific time zone or locale. I've also read a lot fo the docs on NSDateFormatter, NSCalendar, NSDateComponents, NSlocale, and NSTimeZone.
I'm trying to do calculations based on two specific Pacific time zones. For example, I want to be able to count the number of days from date A to date B. I don't want to 'hack' it by parsing strings, as I want things like DST to be calculated as well.
Can anyone recommend a way to do this?
Edit: Found solution:
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSTimeZone *zone = [NSTimeZone timeZoneWithName:@"PST"];
[calendar setTimeZone:zone];
NSDateComponents *comp = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:date];
date = [calendar dateFromComponents:comp];
[calendar release];
This results in a date localized to Pacific time. I know this causes problems with different locales, but my app is unique, and this is justified.
I can then compare dates using the division by 86400 as was posted.
Although, it seems like overkill - a lot of extra work - perhaps there is a shorter way to get a date with a specific time zone?