Different day formatting when using NSDateFormatter on OS X Mavericks and Yosemite

Given the following program:

#import <Foundation/Foundation.h>

int main(int argc, char *argv[]) {
    @autoreleasepool {
        NSDateFormatter *f = [[NSDateFormatter alloc] init];
        f.timeStyle = NSDateFormatterNoStyle;
        f.dateStyle = NSDateFormatterMediumStyle;
        f.calendar = [NSCalendar autoupdatingCurrentCalendar];
        f.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
        f.locale   = [NSLocale localeWithLocaleIdentifier:@"ru"];

        NSDate *feb_01_2012 = [NSDate dateWithTimeIntervalSince1970:1328054400];

        NSLog(@"%@", [f stringFromDate:feb_01_2012]);
    }
}

      

When compiled on OS X, Yosemite produces the following output:

2014-12-08 22:31:49.109 Untitled[14149:1398844] 1 . 2012 .

      

However, when compiled on OS X Mavericks, it gives a slightly different output (note padding zeros on the day):

2014-12-08 22:27:01.890 formatter[54709:507] 01 . 2012 .

      

Any ideas why this might be happening? The error is only displayed for ru

locale: - \

UPDATE: Found a way to get the same number of zeros on both machines. Usage +dateFormatFromTemplate:options:locale:

gives the expected result:

NSLocale *l = [NSLocale localeWithLocaleIdentifier:@"ru"];
f.locale = l;
f.dateFormat = [NSDateFormatter dateFormatFromTemplate:@"yMMMd"
                                               options:0
                                                locale:l];

      

+3


source to share


2 answers


Maybe different average date format settings?



enter image description here

0


source


Perhaps try to specify the Russian language more strictly. Eg [NSLocale localeWithLocaleIdentifier:@"ru_RU"];

. I can assume that the locale with the ru

default identifier is using different locales in another version of OS X. Although this is still weird ...



And just to remind, you can see a list of all locales available with [NSLocale availableLocaleIdentifiers]

.

0


source







All Articles