I have a problem on parsing a date in IOS. Here is the date I got:
2013-12-22T20:30:58.020Z
and I cannot parse this date with the following code block:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'hh:mm:ss.SSSZ"];
entity.updatedAt = [dateFormatter dateFromString:dateString];
What is wrong with this formatting?
[EDIT]
When I changed my hour format to HH, it worked in simulator. However hh works fine while debugging in device. Do you have any opinions about this inconsistency?
You're using hh
, which is the 12-hour clock - but you've provided a value of 20. You want HH
, which is the 24-hour clock:
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
See more on this question at Stackoverflow