NSDate - 将日期转换为GMT [英] NSDate - Convert Date to GMT

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

问题描述

我需要能够将 NSDate 值转换为GMT日期。

I need the ability to convert an NSDate value to a GMT Date.

我该怎么办?将 NSDate 值转换为GMT格式的 NSDate 值,与iPhone设备使用的日期区域设置无关?

How can I go about converting an NSDate value to a GMT formatted NSDate value, independent of whatever date locale settings the iPhone device is using?

推荐答案

    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];

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

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