5
A
回答
11
时区可应用于NSDateFormatter,您可以根据这些时区生成区分时差的NSDate变量。
NSString* input = @"2013-08-03T05:38:39.590Z";
NSString* format = @"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
// Set up an NSDateFormatter for UTC time zone
NSDateFormatter* formatterUtc = [[NSDateFormatter alloc] init];
[formatterUtc setDateFormat:format];
[formatterUtc setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
// Cast the input string to NSDate
NSDate* utcDate = [formatterUtc dateFromString:input];
// Set up an NSDateFormatter for the device's local time zone
NSDateFormatter* formatterLocal = [[NSDateFormatter alloc] init];
[formatterLocal setDateFormat:format];
[formatterLocal setTimeZone:[NSTimeZone localTimeZone]];
// Create local NSDate with time zone difference
NSDate* localDate = [formatterUtc dateFromString:[formatterLocal stringFromDate:utcDate]];
NSLog(@"utc: %@", utcDate);
NSLog(@"local: %@", localDate);
[formatterUtc release];
[formatterLocal release];
1
尝试这样的:
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
NSDate* utcTime = [dateFormatter dateFromString:@"2013-08-03T05:38:39.590Z"];
NSLog(@"UTC time: %@", utcTime);
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
[dateFormatter setDateFormat:@"M/d/yy 'at' h:mma"];
NSString* localTime = [dateFormatter stringFromDate:utcTime];
NSLog(@"localTime:%@", localTime);
希望它可以帮助你.... [如何时间转换为iPhone设备的时区?(HTTP的
+0
Yessss它做到了。非常感谢好友 –
相关问题
- 1. 时区转换到本地
- 2. 从时区转换-500时间到设备所在的时区
- 3. 从时区转换为日期至设备当地时区和日期
- 4. 将时区从一个时区转换为当地时区
- 5. 日期转换为本地时区
- 6. 获取设备的本地时区
- 7. 如何将时间转换为iPhone设备的时区?
- 8. 不同地区的时区转换
- 9. 转换本地时区PST时区在C#
- 10. unble时间转换为本地时区,即北京时间
- 11. JavaScript:使用时区将UTC时间转换为本地时间
- 12. 本地日期,时间和时区值转换为utc时区在php
- 13. 转换为日期时间为本地时区javascript
- 14. javascript - 将本地时间转换为不同的时区
- 15. 将UTC时间转换为javascript中的本地时区
- 16. Powershell - 将本地时间转换为不同的时区
- 17. 转换本地时间与时区为UTC用的ctime
- 18. UTC日期转换为当地时区
- 19. 从当地时区转换为日期?
- 20. 如何将UTC时间转换为浏览器本地时区?
- 21. C++:将Unix时间转换为非本地时区
- 22. 在Xaml中将UTC日期时间转换为本地时区?
- 23. 使用本地时区将unix时间戳转换为NSdate
- 24. Python:将本地时间转换为另一个时区
- 25. 停止Kendo将时间转换为本地时区
- 26. 时区转换
- 27. 时区转换
- 28. 时区转换
- 29. 在Crystal Reports中将服务器时区转换为本地时区
- 30. 从另一个时区转换为保留Java本地时间的本地时区
可能重复:/ /stackoverflow.com/questions/1081647/how-to-convert-time-to-the-timezone-of-the-iphone-device) –