Question

Are these five statements interchangeable, or is anyone aware of cases where their use would yield different results? From what I gather they are equivalent but I haven't found anything conclusive, and potential differences between the GMT and the UTC variants worry me.

[NSTimeZone timeZoneWithName:@"GMT"];
[NSTimeZone timeZoneWithName:@"UTC"];
[NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[NSTimeZone timeZoneWithAbbreviation:@"UTC"];
[NSTimeZone timeZoneForSecondsFromGMT:0];
Was it helpful?

Solution

According to the docs, CFTimeZone (and by extension, NSTimeZone) uses time zone names, abbreviations, GMT offset, and DST information from the TZ (or "Olsen") Database.

Looking at the source, you'll see that while semantically "GMT" and "UTC" are quite distinct, in practice they're no different: "GMT" is just a zero offset timezone.

Update: While this answer remains true for dates later than 9 April 1968, when dealing with historical dates, it appears Cocoa uses past definitions of GMT that were valid at the date in question (rather than the modern definition). This means GMT and UTC could differ for dates prior to 9 April 1968. See the end of this informative blog post for a detailed exposition.

OTHER TIPS

GMT in nearly all cases means UTC.
But today it is the wrong word for what it is meant to be.
Unfortunatley Apple uses the term GMT, while it should use UTC.

GMT in not existing any more in the sense of UTC (since 1928) but unfortunatley in UK and in Africa this term is still used to denote west european time or west european summer time. The real GMT today is called UT and can differ from UTC by up to 0,9s.

The article on Wikipedia: English | German

However in some computer programms (mail header), for historical reasons (unix) it still is called GMT (in the sense of UTC)

Apple's NSDateFormatter and Internet Dates article uses [NSTimeZone timeZoneForSecondsFromGMT:0]:

static NSDateFormatter *    sRFC3339DateFormatter;
NSString *                  userVisibleDateTimeString;
NSDate *                    date;

// If the date formatters aren't already set up, do that now and cache them
// for subsequence reuse.

if (sRFC3339DateFormatter == nil) {
    NSLocale *                  enUSPOSIXLocale;

    sRFC3339DateFormatter = [[NSDateFormatter alloc] init];

    enUSPOSIXLocale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];

    [sRFC3339DateFormatter setLocale:enUSPOSIXLocale];
    [sRFC3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];
    [sRFC3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top