我正在尝试转换 NSString
到 NSDate
随着时间的推移。这就是我现在正在做的事情:
NSString *myDateIs= @"2012-07-14 11:30:40 AM ";
NSDateFormatter* startTimeFormat = [[NSDateFormatter alloc] init];
[startTimeFormat setDateFormat:@"YYYY-MM-dd hh:mm:ss a "];
NSDate*newStartTime = [startTimeFormat dateFromString:myDateIs];
输出为
2012-07-14 06:00:40 +0000
.日期正确,但时间不正确。我怎样才能得到正确的时间?
谢谢。
最佳答案
你得到的时间是格林威治标准时间,把它转换成本地时间。
NSDateFormatter* local = [[[NSDateFormatter alloc] init] autorelease];
[local setTimeZone:[NSTimeZone timeZoneWithName:@"EST"]];
[local setDateFormat:@"YYYY-MM-dd hh:mm:ss a"];
NSString* localSTR = [local stringFromDate: newStartTime];
关于iphone - 如何随时间将 NSString 转换为 NSDate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11500147/