MTA MTA - 6 months ago 24
Objective-C Question

Getting date from [NSDate date] off by a few hours

I am using

NSDate *date = [NSDate date];

for getting the date, but the date I get is off by 2 hours.


NSDate objects don't have time zones; they represent an absolute moment in time. However, when you ask one for its description (by printing it in an NSLog, e.g.), it has to pick a time zone. The most reasonable "default" choice is GMT. If you're not in GMT yourself, the date will seem to be incorrect, by the amount of your own offset.

You should always use an NSDateFormatter, setting its timezone to yours, before displaying a date.