NSDateFormatter, NSDate, UTC and weird date format

I have a very strange date format available to me through JSON. for example - "July 18, 2010 02:22:09"

These dates are always UTC. I parse the date with NSDateFormatter and set timeZone to UTC ...

NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
[inputFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[inputFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]];
[inputFormatter setDateFormat:@"MMMM, dd yyyy HH:mm:ss"];
NSDate *formatterDate = [inputFormatter dateFromString:dtStr];

However, the date when it is registered appears with the offset of my device ...

"2010-07-18 02:22:09 -0600"

What am I doing wrong here?

+3
source share
1 answer

I think this is because NSDate does not use UTC time zone. The docs talk about this NSDate description method:

YYYY-MM-DD HH: MM: SS ± HHMM, ± HHMM GMT (, "2001-03-24 10:45:32 +0600" ).

, . NSDate , . ? ? ?

+2

Source: https://habr.com/ru/post/1755426/


All Articles