Question

I am having problems with my code and not sure what is wrong with it.

NSString* dateFormat1 = @"EEE MMM dd HH:mm:ss V yyyy";
NSString* dateString1 = @"Fri Jul 26 00:00:00 PHT 2013";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:dateFormat1];

My result for iOS5.1:

2013-08-02 11:59:08.459 MySandbox[41502:c07] 2013-07-25 16:00:00 +0000

For iOS 6.0

2013-08-02 12:02:37.454 MySandbox[41581:c07] (null)

*Note, I used V, instead of zzz or Z because it still is null. *Note 2, I tried to change PHT to PST and it worked. Changed it to JST, it didn't work.

I am guessing that I am not using the correct format. Not really sure which I should use.

*Note 3, as per this question, there really was a change in iOS5 and iOS6 so I guess that is the reason why iOS5 worked.

Was it helpful?

Solution

According to these docs from Apple, NSDateFormatter uses the Unicode date format patterns, which are part of "Unicode Technical Standard #35". This standard is evolving, and iOS 5 uses version 19 while iOS 6 uses version 25.

You can read about the supported values for the time zone in "Appendix J: Time Zone Display Names" (version 19 or version 25).

I am not exactly sure why PHT was supported before and not it isn't. But in general, the best advice I can give is to avoid using time zone abbreviations. While PHT is unique, there are many other abbreviations that are ambiguous. See the list here.

Instead, you should uses the IANA time zone name whenever possible. (The tr-35 standard calls this the "Golden Zone"). In your case, it would be Asia/Manila. You can find a full list here. I am not an Objective C developer, so I'm not sure exactly how you would use this in your input string. You can try the VVVV format specifier, but I'm not sure if it directly accepts the IANA name or not.

You might want to check the results from [NSTimeZone abbreviationDictionary] as shown in this answer. In that post, it does show PHT = "Asia/Manila", but I assume by the date that it was posted that these were generated from iOS 5.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top