I have tried setting the timezone and locale of the NSDateFormatter but I can't seem to get anything to work. Here is the code
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM/dd/yyyy hh:mm:ss"];
NSString *myFireDateString=[@"9/17/11" stringByAppendingString:@" 09:00:00"];
NSDate *myFireDate = [dateFormat dateFromString:myFireDateString];
NSLog(@"The datestring is is %@",myFireDateString);
NSLog(@"The formatted date is %@",myFireDate);
Here is the output:
The datestring is is 9/17/11 09:00:00
The formatted date is 2011-09-17 开发者_JAVA技巧13:00:00
You need to set a timezone to your dateFormatter:
[dateFormatter setTimeZone:[NSTimeZone defaultTimeZone];
See NSDate from NSString , shows the previous day
精彩评论