iPhone:NSDate 将 GMT 转换为本地时间 [英] iPhone: NSDate convert GMT to local time

查看:19
本文介绍了iPhone:NSDate 将 GMT 转换为本地时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个 API 调用以以下格式返回日期/时间:2010-10-10T07:54:01.878926

I currently have an API call returning me a date/time in the format: 2010-10-10T07:54:01.878926

我可以假设这是格林威治标准时间吗?我还将它转换为 NSDate 对象.有没有办法使用本地 iPhone 时间重新计算时间?

Can I assume this is GMT? I also converted this to an NSDate object. Is there a way to use the local iPhone time to recalculate the time?

推荐答案

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm";

NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[dateFormatter setTimeZone:gmt];
NSString *timeStamp = [dateFormatter stringFromDate:[NSDate date]];
[dateFormatter release];

这篇关于iPhone:NSDate 将 GMT 转换为本地时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆