I want to get a NSDate object from a string of date, but it returns nil. What am I doing wrong? Thanks!
NSString *dateString = @"2012-04-05T13:27:32.369Z";
NSDateFormatter* df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"YYYY-MM-dd'T'HH:mm:ss.SSSZ"];
NSDate* date = [df dateFromString:dateString];
NSLog(@"1%@",date);
[df release];
It should be
yyyy
for yearsUse NSDateFormatter to get a NSDate then use - (NSTimeInterval)timeIntervalSince1970 to get the seconds since 1970.
Hope it helps.
The "Z" must be quoted:
NSLog output:
Keep in mind that
NSLog
uses theNSDate
default formatter with the current timezone.See: Date_Field_Symbol_Table