I am facing a bug (?) with NSDateFormatter. First of all, here's a method I use to get the current NSDate
as NSString
(converted in a not-so-easy-to-read format because it's sent to a web service) :
+ (NSString *) nowToUTCDate {
NSDate *now = [NSDate date];
NSDateFormatter* df_utc = [[NSDateFormatter alloc] init];
[df_utc setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
[df_utc setDateFormat:@"yyyyMMddHHmmss"];
return [df_utc stringFromDate:now];
}
On iOS <= 7.0.4, the result gave me : 20140307203040
(even though I use the 12h format).
On my iPhone (iOS 7.0.6), the result is : 20140307083346 PM
(only if I use the 12h format).
Boom, a " PM" appears ! Why ? I am using the HH
string to explicitly ask for a 24h format (as said here).
As a workaround, I wrote this solution :
NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[df_utc setLocale:enUSPOSIXLocale];
Is that a bug that was introduced by Apple to the last version of iOS or am I misunderstanding something ?
Thank you for your help!