Im trying to return the localized form of the setDateFormat of "H:mm" in iOS.
Most localizations would return the 24 hour form, but for Japanese localization, it is returning the string with the AM/PM开发者_开发知识库 present (obviously in the Kanji form).
According to this: http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns , 'H' would return the 24 hour form the the time, and it is working for other East Asian localizations ( tested Korean and Chinese localization).
Can someone provide insight on why iOS is displaying the AM/PM even though I didn't specify it to show for Japanese localization?
Thank you.
Can you share some source code as to how you are setting/getting the Japanese localization?
Here's what I get:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"H:mm"];
NSDate *date = // some time after noon
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en"]];
NSLog(@"en: %@", [formatter stringFromDate:date]);
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"ja"]];
NSLog(@"jp: %@", [formatter stringFromDate:date]);
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"ko"]];
NSLog(@"ko: %@", [formatter stringFromDate:date]);
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]];
NSLog(@"cn: %@", [formatter stringFromDate:date]);
This displays:
en: 14:06
jp: 14:06
ko: 14:06
cn: 14:06
Or using the default formatter styles, and re-running it:
[formatter setDateStyle:NSDateFormatterShortStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
Results:
en: 1/21/11 2:13 PM
jp: 11/01/21 14:06
ko: 11. 1. 21. 오후 2:06
cn: 11-1-21 下午2:06
Check that Settings->General->Date&Time has 24-Hour Time set to ON
精彩评论