2010-11-16 4 views
0

J'ai un NSDateFormatteriphone - problème NSDateFormatter?

[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"]; 

pour la valeur: 2010-01-01 05:00:00.000 il renvoie la valeur correcte

mais pour la valeur: 2010-01-01 05:22:00.000 retourne null.

Selon la documentation si je suis correct pour la minute, je suppose d'utiliser "mm" Alors, quel est le problème avec mon code et pourquoi il revient nul?

Répondre

4
NSDateFormatter * f = [[NSDateFormatter alloc] init]; 
[f setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"]; 
NSLog(@"%@", [f dateFromString:@"2010-01-01 05:00:00.000"]); 
NSLog(@"%@", [f dateFromString:@"2010-01-01 05:22:00.000"]); 
[f release]; 

Journaux:

2010-11-16 16:44:11.867 EmptyFoundation[42477:a0f] 2010-01-01 05:00:00 -0700 
2010-11-16 16:44:11.868 EmptyFoundation[42477:a0f] 2010-01-01 05:22:00 -0700 

Il est donc l'analyse des choses correctement. Ainsi, vous faites quelque chose de mal ailleurs.

+0

Désolé mon erreur le problème était ailleurs dans mon code – aryaxt

0

Cela me semble propre. Je l'ai essayé et obtenu des résultats corrects:

NSDateFormatter *f = [[NSDateFormatter alloc] init]; 
[f setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"]; 
NSDate *date = [f dateFromString:@"2010-01-02 03:44:55.666"]; 

NSLog(@"%@",date); 
NSDateFormatter *f2 = [[NSDateFormatter alloc] init]; 
[f2 setDateFormat:@"d. MMMM yyyy HH mm ss SSS"]; 
NSString *s = [f2 stringFromDate:date]; 

NSLog(@"Date is really %@",s); 

Retourné la sortie suivante:

2010-11-16 18:48:35.221 Test3[6407:207] 2010-01-02 03:44:55 -0500 
2010-11-16 18:48:35.223 Test3[6407:207] Date is really 2. January 2010 03 44 55 666