0

On iOS 5 (simulator and device), when I tried to parse a date string with timezone ICT, it just returns (null). One strange thing is that this timezone used to work fine in iOS4.3.

NSString *inputDateStr = @"Fri, 06 Apr 2012 13:00:00 ICT";
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss zzz"];
NSDate *inputDate = [df dateFromString:inputDateStr];
NSLog(@"--- INPUT %@ -> %@ ---",inputDateStr, inputDate);

--- INPUT Fri, 06 Apr 2012 13:00:00 ICT -> (null) ---

But when I tried other timezone, like PST, it works !?

NSString *inputDateStr = @"Fri, 06 Apr 2012 13:00:00 PST";

--- INPUT Fri, 06 Apr 2012 13:00:00 PST -> 2012-04-06 21:00:00 +0000 ---

I printed out [NSTimeZone abbreviationDictionary] and still see ICT in there. So this timezone should be still valid. So, why do I get (null)?

Hlung
  • 13,850
  • 6
  • 71
  • 90

1 Answers1

0

Time zone names are locale specific and can mean something else in different languages or not exist at all.

eg.

ICT Îles Crozet Time +4
ICT Indochina Time +7

Use GMT+XX for a stable functionality.

EDIT:

See this link for more information about time zones: http://unicode.org/repos/cldr/trunk/docs/web/tr35.html#Time_Zone_Fallback

Note the section is called "Time Zone Display Names". These names were never intented to be used for parsing. They are meant to be displayed (e.g. as the result of the ZZZ pattern).

Sulthan
  • 128,090
  • 22
  • 218
  • 270
  • Yeah, that is sure more stable. But using GMT doesn't have daylight savings. – Hlung May 02 '12 at 09:18
  • PST does not have daylight saving either. Note there is "Pacific Standart Time (PST)" and "Pacific Daylight Time (PDT)". However, PST can also mean "Pakistan Standard Time" and in my locale (cs-CZ) PST is not available at all. – Sulthan May 02 '12 at 09:23
  • May be I can set NSDateFormatter object's locale property to get a particular timezone to work? – Hlung May 02 '12 at 09:43
  • That would work but it will also change the language of the day & month name patterns. Maybe you could get the correct time zone as a `NSTimeZone` instance and calculate the GMT offset for `NSDateFormatter` pattern from the `secondsFromGMT` method. – Sulthan May 02 '12 at 09:53
  • I'm not sure that "language" is the real reason behind this. But it sounds sensible to me. I ended up using GMT. I also store the timezone string that Rails "ActiveSupport::TimeZone" uses. so I can later convert it back. More info on my other post -> http://stackoverflow.com/questions/10382932/nstimezone-how-can-i-use-timezonewithname-if-i-have-only-the-city-name – Hlung May 31 '12 at 05:56