Search code examples
iostimezonenstimezone

NSTimeZone and special time zone area Etc


Is it correct to assume that NSTimeZone timeZoneWithName: in iOS 7 accepts both time zone IDs with non-special areas (as in America/New_York) and with the special area (as in Etc/UTC) but that NSTimeZone name will never return the special area (but would return e.g. Europe/London instead)?

Who can confirm this?


Solution

  • I don't think that's a safe assumption. On OS X, in my time zone and locale (US English, UTC-6), I can run the following code:

        NSTimeZone *utc = [NSTimeZone timeZoneWithName:@"Etc/UTC"];
        NSTimeZone *london = [NSTimeZone timeZoneWithName:@"Europe/London"];
        NSLog(@"utc name = %@", [utc name]);
        NSLog(@"london name = %@", [london name]);
    

    Which gives the following output:

    utc name = Etc/UTC

    london name = Europe/London

    So If a time zone was given a special area in instantiating it, it will continue to use that with its name. As an added layer of complication, using +timeZoneWithAbbreviation: will also get different names, e.g.:

        NSTimeZone *utc2 = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
        NSLog(@"utc2 name = %@", [utc2 name]);
    

    utc2 name = GMT