0

I am pulling a date from JSON in the format of "1900-01-01T00:00:00-06:00"

The code I am currently trying (and failing to parse with) is this

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZ"];
tempDate = [formatter dateFromString:trimmedString];

I then want to display what I pull in the MM-dd-yyyy format after I actually get the date back in the correct format.

I am not sure of how many SSS and ZZ's I need at the end, and have tried multiple combinations to no avail. Any Suggestions?

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
dwilkins
  • 3
  • 1
  • 1
    "S" are sub seconds and you don't have them in your format so I don't think you need "S" at all. – Marcin Kuptel May 14 '13 at 20:25
  • Check out: http://stackoverflow.com/questions/14435954/parse-json-date-into-nsdate-depending-user-settings – savner May 14 '13 at 20:28
  • 2
    Your format does not match your data. See http://www.unicode.org/reports/tr35/tr35-25.html#Date_Format_Patterns. (In particular, you want to end your format with "ZZZZZ".) – Hot Licks May 14 '13 at 20:29

1 Answers1

3

You need five "Z"s

[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
dalton_c
  • 6,876
  • 1
  • 33
  • 42