Na symulatorze i urządzeniu iOS5, NSDateFormatter nie pokazuje skrótu strefy czasowej dla "Azja/Kalkuta "dla specyfikatora" z "lub" zzz ".NSDateFormatter nie pokazuje skrótu strefy czasowej dla "Azja/Kolkata" dla specyfikatora "z" lub "zzz", tylko przesunięcie GMT
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"Asia/Kolkata"];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
dateFormatter.dateFormat = @"z"; // or @"zzz"
dateFormatter.timeZone = timeZone;
NSLog(@"date string: %@", [dateFormatter stringFromDate:[NSDate date]]); // "GMT+05:30", expected "IST"
NSLog(@"time zone abbreviation: %@", [timeZone abbreviationForDate:[NSDate date]]); // "IST"
Spodziewam powyższy kod do wyjścia:
IST
IST
ale wyprowadza:
GMT+05:30
IST
EDIT
Ustawienie locale do indian lokalizacji nie wydaje się pomagać.
NSLocale *indianEnglishLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_IN"] autorelease];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"Asia/Kolkata"];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setLocale:indianEnglishLocale];
[dateFormatter setDateFormat:@"z"]; // or @"zzz"
[dateFormatter setTimeZone:timeZone];
NSLog(@"date string: %@", [dateFormatter stringFromDate:[NSDate date]]); // "GMT+05:30", expected "IST"
NSLog(@"time zone abbreviation: %@", [timeZone abbreviationForDate:[NSDate date]]); // "IST"
Spodziewam powyższy kod do wyjścia:
IST
IST
ale wyprowadza:
GMT+05:30
IST
Czy to błąd? czy robię coś źle? People have mentioned that NSDateFormatter has bugs, especially when a time zone is specified in the format string. Could this be one of those bugs?
Należy pamiętać, że w nowoczesnych iOS jedyny sposób zalecany przez firmę Apple w użyciu datę formatter to: https://stackoverflow.com/a/42370648/294884 – Fattie