Possible Duplicate:
Getting date from [NSDate date] off by a few hours
I want to calculate the actual day's midnight time using the actual day's date here is the code:
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"dd/MM/yyyy"];
NSDate *today = [NSDate date];
NSString *todayStr = [NSString stringWithFormat:@"%@ 12:59 PM",[formatter stringFromDate:today]];
NSLog(@"%@",todayStr);
[formatter setDateFormat:@"dd/MM/yyyy hh:mm a"];
NSDate *midNight = [formatter dateFromString:todayStr];
NSLog(@"%@",midNight);
But the log I get is :
23/01/2013 12:59 PM
2013-01-23 10:59:00 +0000
Why does midNight
isn't the actual midnight and why does it have a different format from formatter
?