At AmazonSDKUtil.m we have the following methods:
+(NSDate *)convertStringToDate:(NSString *)string usingFormat:(NSString *)dateFormat { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:dateFormat]; [dateFormatter setLocale:[AmazonSDKUtil timestampLocale]]; [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; NSDate *parsed = [dateFormatter dateFromString:string]; NSDate *localDate = [parsed dateByAddingTimeInterval:_clockskew]; [dateFormatter release]; return localDate; } +(NSString *)convertDateToString:(NSDate *)date usingFormat:(NSString *)dateFormat { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; [dateFormatter setDateFormat:dateFormat]; [dateFormatter setLocale:[AmazonSDKUtil timestampLocale]]; NSDate *realDate = [date dateByAddingTimeInterval:-1*_clockskew]; NSString *formatted = [dateFormatter stringFromDate:realDate]; [dateFormatter release]; return formatted; }
In older versions of the SDK, the locale and time zone were incorrectly set to en_US and GMT . This can cause problems depending on the locale of your device and time zone settings. The latest version of the SDK fixed the problem. If for some reason you cannot update the SDK, you can change AmazonSDKUtil.m and explicitly set the language and time zone.
EDIT:
If you run the following code snippet on iOS 6 and iOS 7, you can see how setting the locale affects the date format.
NSDateFormatter *dateFormatter = [NSDateFormatter new]; dateFormatter.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss z"; dateFormatter.timeZone = [NSTimeZone timeZoneWithName:@"PDT"]; dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"]; NSString *dateWithoutTimezoneAndLocale = [dateFormatter stringFromDate:[NSDate date]]; NSLog(@"Date 1: %@", dateWithoutTimezoneAndLocale); dateFormatter.timeZone = [NSTimeZone timeZoneWithName:@"GMT"]; dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; NSString *dateWithTimezoneAndLocale = [dateFormatter stringFromDate:[NSDate date]]; NSLog(@"Date 2: %@", dateWithTimezoneAndLocale);
On iOS 6
Date 1: Wed, 25 Sep 2013 16:25:29 PDT Date 2: Wed, 25 Sep 2013 23:25:29 GMT
On iOS 7
Date 1: Wed, 25 Sep 2013 16:24:11 GMT-7 Date 2: Wed, 25 Sep 2013 23:24:11 GMT
As you said earlier, the behavior of NSDateFormatter has changed in iOS 7; however, the main reason for this problem is that you are not explicitly setting the locale to en_US . If the locale is set to a value other than en_US , this can cause a problem. That's why we explicitly set the locale in the latest version of our SDK so that it works on devices with any locale settings.
Hope this makes sense
source share