NSDateFormatter is disabled for one hour

I am trying to format a date from an RSS feed:

Mon, 02/27/2012 10:33:00 PM EDT (format from the RSS feed)

To:

Mon, 27 Feb 2012 10:33

Here is what I do in the code:

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"EE, d MM yyyy HH:mm:ss zzz"]; NSDate *date = [dateFormat dateFromString:@"Mon, 27 Feb 2012 10:33:00 EDT"]; [dateFormat setDateFormat:@"EE, d MMM yyyy hh:mm a"]; formatedDateLabel.text = [dateFormat stringFromDate:date]; [dateFormat release]; 

However, this always outputs:

Mon, Feb 27, 2012 9:33 AM

Please note that my devices are set to EST. I tried setting the date format to fit EDT, but that does not seem to make any difference.

Any ideas on what I'm doing wrong?

+4
source share
1 answer

You are not doing anything wrong. The reason this happens is because the internal representation of EDT and EST of NSTimezone identical:

 // These objects are the same: [NSTimeZone timeZoneWithAbbreviation:@"EST"]; [NSTimeZone timeZoneWithAbbreviation:@"EDT"]; 

NSDateFormatter dateFromString: smart enough to know that a date from February marked by EDT should have a GMT offset of -4 instead of -5, although this is not a well-formed date. But when you use it to display dates, if its time zone is set to EST or EDT (which it considers to be the same), it will use the appropriate time zone based on whether the day saving is currently in effect.

+2
source

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


All Articles