Team,
I am comparing the date which is formed from string using NSDateFormatter with the iOS system date. The below statement returns true when the system date time settings is set with 24-Hour Time ON, but the same code returns false when 24-Hour Time OFF.
Problematic Code:
if ([(NSDate*)[NSDate date] compare:currDate] == NSOrderedAscending) {
// -- Code -- This is executed only when the 4-Hour Time ON
}
I am confused. The string using which I am getting the date is in 24 hours format. Is this a problem? Or anything else?
Date Formatting Code:
-(NSDate *)getDateFromString:(NSString *)dateString{
NSDateFormatter* fmt = [[NSDateFormatter alloc] init];
[fmt setDateFormat:@"dd MMM yyyy hh:mm:ss"];
[fmt setTimeZone:[NSTimeZone systemTimeZone]];
[fmt setFormatterBehavior:NSDateFormatterBehaviorDefault];
return [fmt dateFromString:dateString];
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…