views:

63

answers:

3

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

A: 

Use NSDate *now = [NSDate date];

I am using it and giving me perfect result.

Javal Nanda
this method uses the -init method, ie you can read it as [[[NSDate alloc] init] autorelease]; There should be no difference.
fluchtpunkt
A: 

Maybe your timezone is wrong in your iPhone simulator. Press the home button, go to settings.app and correct it ;)

Sander Backus
I can't find anywhere in the settings to change the time. The time on the status bar is also correct.
Smikey
A: 

Use NSDateFormatter to localize the date:

NSLog(@"%@",[NSDateFormatter localizedStringFromDate:[NSDate date] dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle]); 
Sander Backus
That does indeed display the correct date. However, the date when initialised as above is still wrong by an hour... :o
Smikey
NSDate works in GMT "The sole primitive method of NSDate, timeIntervalSinceReferenceDate, provides the basis for all the other methods in the NSDate interface. This method returns a time value relative to an absolute reference date—the first instant of 1 January 2001, GMT."
Sander Backus