Objective-C将NSDate设置为当前UTC [英] Objective-C setting NSDate to current UTC
本文介绍了Objective-C将NSDate设置为当前UTC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种简单的方法可以使用当前的UTC日期/时间初始化 NSDate
?
Is there an easy way to init an NSDate
with the current UTC date/time?
推荐答案
[NSDate date];
您可能想要创建一个类别类似这样的事情:
You may want to create a category that does something like this:
-(NSString *)getUTCFormateDate:(NSDate *)localDate
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
[dateFormatter setTimeZone:timeZone];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *dateString = [dateFormatter stringFromDate:localDate];
[dateFormatter release];
return dateString;
}
这篇关于Objective-C将NSDate设置为当前UTC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文