简体   繁体   English

如何在iPhone中将NSDate转换为UTC格式

[英]How to convert NSDate into UTC format in iPhone

I need to convert current date into UTC format, i have done the following and got the correct UTC date, below is my source code 我需要将当前日期转换为UTC格式,我已完成以下操作并获得了正确的UTC日期,以下是我的源代码

NSDate *currDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
[dateFormatter setTimeZone:timeZone];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss zzz"];
NSString *dateString = [dateFormatter stringFromDate:currDate];
NSLog(@"%@",dateString);

I am getting date in this format 2013-05-01 23:11:02 GMT only i want UTC name instead on GMT what conversion do i need to do for this. 我仅以这种格式获取日期2013-05-01 23:11:02 GMT我只想在GMT上使用UTC名称,我需要为此进行什么转换。

如果您只关心文本而不是字符串,请替换:

 NSString *convString = [dateString stringByReplacingOccurrencesOfString:@"GMT" withString:@"UTC"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM