Tuesday, July 3, 2012

NSDateFormatter will not work for the date before 1970 ?


double seconds = -62167464057.000;

NSDate *oldDate = [NSDate dateWithTimeIntervalSince1970:seconds];

MELog("oldDate = %@", oldDate);//oldDate = 0002-12-29 03:59:03 +0000

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init]  autorelease];

[dateFormatter setDateStyle:NSDateFormatterNoStyle];

[dateFormatter setTimeStyle:NSDateFormatterShortStyle];


NSString *formattedDateString = [dateFormatter stringFromDate:oldDate];

NSLog(@"formattedDateString = %@", formattedDateString);//formattedDateString = 3:57 AM


In the above code, the date component has the time 3:59, But when we format it to extract the time field, we are getting 3:57
My timezone is London, so it should return 3:59
Is this because of we are trying to format a date before 1970 ? Please confirm if anyone knows.

Its discussing here

No comments:

Post a Comment