Quando si utilizza il tempo di 24 ore, l'ora specificatore deve essere la S maiuscola come questo:
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
Controllare qui per i prescrittori corrette: http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
Tuttavia, è necessario impostare l'impostazione internazionale per la data formattatore:
// Set the locale as needed in the formatter (this example uses Japanese)
[dateFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"ja_JP"]];
codice di lavoro completa:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss zzz"];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"ja_JP"]];
NSDate *capturedStartDate = [dateFormatter dateFromString: @"2012-09-16 23:59:59 JST"];
NSLog(@"Captured Date %@", [capturedStartDate description]);
uscite (in GMT):
Captured Date 2012-09-16 14:59:59 +0000
Hey @danielbeard, come u detto verrà visualizzato il tempo GMT, che mostrerà differenza di tempo di 9 ore dopo la data esatta. Come ottenere la data esatta dalla stringa .. ?? .. – NiKKi
Le date non hanno fusi orari, ma è possibile ottenere una rappresentazione di stringa in un fuso orario con 'stringFromDate' con NSDateFormatter impostato sopra. – danielbeard
Vedi qui per maggiori dettagli http://stackoverflow.com/questions/1862905/nsdate-convert-date-to-gmt – danielbeard