1
我需要爲當前日期轉換爲UTC格式,我也做了以下內容並得到了正確的UTC日期,下面是我的源代碼如何的NSDate轉換爲UTC格式在iPhone
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只有我希望UTC的名稱,而不是格林威治標準時,我需要做什麼轉換。
嘗試此鏈接:http://stackoverflow.com/questions/1268509/convert-utc-nsdate-to-local-timezone -objective-C – 2013-05-01 13:48:28