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
23 May 2013 15:37:00
is a 24 hour format string.So the correct date is obtained using the 24 hour format date formatter .Thats it
So use
[fmt setDateFormat:@"dd MMM yyyy HH:mm:ss"];
See Apple's Technical Q&A 1480.
You need to set the date formatter's locale to the special locale of en_US_POSIX
. You also need to specify a 24-hour hour format - HH
, not hh
.
-(NSDate *)getDateFromString:(NSString *)dateString{
NSLocale *posix = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
NSDateFormatter* fmt = [[NSDateFormatter alloc] init];
[fmt setLocale:posix];
[fmt setDateFormat:@"dd MMM yyyy HH:mm:ss"];
return [fmt dateFromString:dateString];
}