我已经尝试设置NSDateFormatter的时区和区域设置,但我似乎无法使用任何东西。这是代码
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);
这是输出:
日期字符串是9/17/11 09:00:00
格式化日期为2011-09-17 13:00:00
答案 0 :(得分:0)
您需要为dateFormatter设置时区:
[dateFormatter setTimeZone:[NSTimeZone defaultTimeZone];