Qui il frammento di codice completo per confrontare due NSDate che si possono trovare più utile in base alla query.
NSCalendar *myCal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSString *str [email protected]"12:15, 01 15 2012 AM";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"hh:mm, dd MM yy a"];
NSDate *refDate = [formatter dateFromString:str];
NSDate *today = [NSDate date];
NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit;
NSDateComponents *difference = [myCal components:unitFlags fromDate:refDate toDate:today options:0];
NSLog(@"%@",difference);
------------------------------ quello che otterrete è -------- ---------------------------------
Anno civile: 0 Mese: 0 Giorno: 0 Ora: 1 Minuto: 19
fonte
2012-07-17 10:24:51
funziona alla grande. Grazie mille. –
Si noti che questo può valutare un numero negativo di minuti, a seconda di quale data è precedente. O nega il numero se è negativo, o usa la funzione 'abs' o' fabs'. –
grazie come sempre per quel suggerimento @ Peter –