J'ai une date au format NSString avec ce contenu: 29/02/2012 00:00:00erreur NSDateFormatter conversion de la date de chaîne
Je suis en train de le convertir en objet NSDate afin de faire des comparaisons using:
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"dd/MM/yyyy hh:mm:ss"];
Mais quand j'utilise la méthode dateFromString: j'obtiens une valeur nulle.
Qu'est-ce qui me manque?
Merci.
-Edit-
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"dd/MM/yyyy hh:mm:ss a"];
NSLog(@"INFO -> Test Date: %@",[df dateFromString:testQuestions.endDate]);
NSLog(@"INFO -> Test Date String: %@",testQuestions.endDate);
if ([[df dateFromString:testQuestions.endDate] earlierDate:[NSDate date]])
{
currentTestIsBeingSolved = NO;
}
Log:
2012-04-09 22:15:29.073 Otsuka On[27184:707] INFO -> Test Date: (null)
2012-04-09 22:15:31.816 Otsuka On[27184:707] INFO -> Test Date String: 29/02/2012 12:00:00 AM
EDIT--
Comme je l'ai suggéré @trudyscousin commencé un nouveau projet et a ajouté ceci:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"dd/MM/yyyy hh:mm:ss a"];
NSLog(@"INFO -> Test Date: %@",[df dateFromString:@"29/02/2012 12:00:00 AM"]);
...
Maintenant, je ne reçois pas de null mais la date n'est pas la même:
2012-04-09 22:26:19.189 TestDate[54705:207] INFO -> Test Date: 2012-02-28 23:00:00 +0000
Que se passe-t-il avec les dates?
Toute configuration dans Xcode?
Merci.
La date imprimée semble directement hors parce qu'il est affiché GMT (notez le fuseau horaire '+ 0000' à la fin de la chaîne). Voir l'une de ces questions: http://stackoverflow.com/search?q=%5Bobjc%5D+nsdate+off –