I have this block of code to read in the ISO 8601 Date/Time specification. The problem is that for some reason, the month doesn't work. Every time I convert it month is "01". What am I doing wrong?
NSDateFormatter *UTCDateFormat = [[NSDateFormatter alloc] init];
[UTCDateFormat setDateFormat:@"yyyy-MM-DD'T'HH:mm:ss'Z'"];
[UTCDateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
[UTCDateFormat setCalendar:[[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease]];
[UTCDateFormat setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]];
NSLog(@"%@", [UTCDateFormat dateFromString:dateString]);
So, for example, if dateString was:
@"2002-03-12T21:13:27Z"
my output would be:
2002-01-12 21:13:27 +0000
Things I have already tried:
Try this
[UTCDateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
DD is the "Day of the year" not the "Day of a month". A great source for looking up NSDateFormatter formats is this table
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With