Search code examples
iphoneobjective-cdatetimensdatenslog

init] returning date an hour in the past?


When I call

NSDate *now = [[NSDate alloc] init]; 

in order to get the current date and time, I check it with:

NSLog(@"Date now: %@", now);

the date outputted is one hour in the past.

2010-10-08 12:04:38.227 MiniBf[1326:207] Now: 2010-10-08 11:04:38 GMT

Is my time zone set incorrectly somewhere perhaps?

Thanks!

Michael


Solution

  • Use NSDateFormatter to localize the date:

    NSLog(@"%@",[NSDateFormatter localizedStringFromDate:[NSDate date] dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle]);