How to find out what time zone for NSDateFormatter when converting from NSDate

I have a function that converts NSString in RFC3339 to NSDate using NSDateFormatter, but I don't know how to take into account the timezone doing the opposite.

The corresponding portion of the string for converting NSDate:

    // The result of a call to systemTimeZone is cached by the app automatically, if the user changes it that change isn't 
    // reflected unless resetSystemTimeZone is called to clear the cache.
    [NSTimeZone resetSystemTimeZone]; 
    NSLocale *enUSPOSIXLocale;
    enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
    [sRFC3339DateFormatter setLocale:enUSPOSIXLocale];
    if ([fromString hasSuffix:@"Z"] || [fromString hasSuffix:@"z"])
    {
        [sRFC3339DateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
    }
    else 
    {
        [sRFC3339DateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
    }

[sRFC3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];

My question is that when converting in the other direction from NSDate to NSString, how do I know what can I call setTimeZone with? When you go from line to NSDate, looking at the absence / presence of Z. But if I have NSDate, how do I know in what time zone to set the formatter?

+3
source share
1 answer

NSDate UTC/GMT. , , , , . "" . , .

+2

All Articles