Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSDateFormatter returns nil for the 2 AM hour

I'm trying to convert a string to an NSDate using the following code:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
NSDate *date= [dateFormatter dateFromString:@"2013-03-10T02:00:00"];

It works fine for all hours except 02:00:00, shown above, which returns nil.

Any ideas?

like image 607
user2154750 Avatar asked Mar 10 '13 21:03

user2154750


1 Answers

This is because of the Daylight Savings Time that took place in the US on 10th March 2013

The System time directly jumps from 1:59 AM to 3:00 AM..
You lose an hour that you had gained on November when the DST came into effect

like image 88
Mr.Anonymous Avatar answered Oct 24 '22 20:10

Mr.Anonymous