Init] return date in the past?

When i call

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

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

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

The displayed date takes 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 timezone incorrect somewhere, maybe?

Thanks!

Michael

+1
datetime objective-c iphone nsdate nslog
source share
4 answers

Use NSDateFormatter to localize the date:

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

I saw this behavior on DatePicker running on iOS 4.1 devices, while on iOS 4.0 and in the previous case this does not happen. I can’t confirm that this is actually the same error.

But I suggest you check to see if this is due to an Apple confirmed date / daylight saving time /4.1 message by running this code in <4.1. Then you will need to decide whether to crack the fix for that particular version / date or wait for the next version of the SDK to fix it and not support 4.1 devices ...

The error I am talking about, I believe that this only happens during dates in the summer (2010: March 28 - October 31).

+1
source share

Use NSDate * now = [NSDate date];

I use it and give the perfect result.

0
source share

Your time zone may be incorrect in your iPhone simulator. Press the home button, go to settings.app and fix it;)

0
source share

All Articles