[英]iPhone: How to convert "yyyyMMddThhmmss" format string to NSDate?
[英]How to convert NSDate into UTC format in iPhone
我需要将当前日期转换为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);
我仅以这种格式获取日期2013-05-01 23:11:02 GMT我只想在GMT上使用UTC名称,我需要为此进行什么转换。
如果您只关心文本而不是字符串,请替换:
NSString *convString = [dateString stringByReplacingOccurrencesOfString:@"GMT" withString:@"UTC"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.