NSDateFormatter, including redundant "PM" in stringFromDate: on iOS 7.0.6

I encountered an error (?) With NSDateFormatter. First of all, here is the method that I use to get the current NSDateas NSString(converted in a format that is not very readable, since it is sent to the 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];
}

In iOS = 7.0.4, the result gave me: 20140307203040(although I use 12h format).

On my iPhone (iOS 7.0.6), the result is: 20140307083346 PM(only if I use the 12th format). Boom, "PM" appears! What for? I use a string HHto explicitly request a 24-hour format (as said here ).

As a workaround, I wrote this solution:

NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[df_utc setLocale:enUSPOSIXLocale];

Is this a bug Apple made in the latest version of iOS, or am I missing something?

!

+4

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


All Articles