【发布时间】:2017-12-07 11:11:45
【问题描述】:
NSString *strUTCTime=@"2017-07-06T10:00:00";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-ddTHH:mm:ss";
NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
[dateFormatter setTimeZone:destinationTimeZone];
NSDate *oldTime = [dateFormatter dateFromString:strUTCTime];
NSString *estDateString = [dateFormatter stringFromDate:oldTime];
NSLog(@"Local time is ===> %@",estDateString);
【问题讨论】:
-
您需要自己调试,或者至少向我们展示一些有用的结果。例如
oldTime是nil,这就是为什么estDateString无论如何都会为零。所以你的问题来自于获得oldTime。事实上,我删除了timeZone的东西来检查我是否可以获得NSDate而不是。它帮助我发现问题出在dateFormat,您需要“转义”T=>dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss"; -
是的,需要转义 T 谢谢。 =====> dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss";
标签: ios objective-c nsdate nsdateformatter