mysterioustrousers / MTDates

A thread safe date calculation library with all the date functions you'll ever need.
BSD 2-Clause "Simplified" License
343 stars 68 forks source link

How to parse 2013-09-27T14:12:14+01:00 #33

Closed tobinharris closed 10 years ago

tobinharris commented 11 years ago

We are dealing with dates in the format 2013-09-27T14:12:14+01:00

I've tried to parse it using

[NSDate mt_dateFromString:postedAt usingFormat: @"yyyy-MM-ddTHH:mm:ss+z"]

...but no cigar.

Any help appreciated :)

atomkirk commented 11 years ago

I think it needs to be: yyyy-MM-dd'T'HH:mm:ss+ZZZZ. Notice the ' around T. I'm not positive how to match that time zone format, but I'm sure it's possible. I would try all combinations of using z, Z, zzz, ZZZ, etc. (http://unicode.org/reports/tr35/tr35-10.html#Date_Format_Patterns).

Post what you learn here.

atomkirk commented 11 years ago

also, here are some common formats that it automatically tries to use: https://github.com/mysterioustrousers/MTDates/blob/master/MTDates/NSDate%2BMTDates.m#L124

yas375 commented 11 years ago

Correct format for the string is yyyy-MM-dd'T'HH:mm:ssz:

[NSDate mt_dateFromString:@"2013-09-27T14:12:14+01:00" usingFormat:@"yyyy-MM-dd'T'HH:mm:ssz"]; // 2013-09-27 13:12:14 +0000

z is used for time zone format (i.e. +01:00, -03:00).

atomkirk commented 11 years ago

Thanks!