我正是如此初始化我NSDateFormatter:转换的NSDate到的NSString不格林尼治标准时间修改
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]];
[dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss z"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
NSDate *date = [NSDate date];
NSString *dateString = [dateFormatter stringFromDate:date];
dateString
现在是:
Thu, 29 Jul 2010 14:58:42 GMT+00:00
我想摆脱的“+ 00:00“
我从http://unicode.org/reports/tr35/tr35-6.html#Time_Zone_Fallback猜测我可能有本地化问题。我正在通过手动删除“+00:00”来解决此问题,但这并不理想。
编辑
我尝试了一些新的方法来创建NSTimeZone,但他们都产生相同的dateString
:
[NSTimeZone timeZoneWithName:@"GMT"];
[NSTimeZone timeZoneWithName:@"UTC"];
[NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[NSTimeZone timeZoneWithAbbreviation:@"UTC"];
对于有趣的问题+1。我无法弄清楚自己。顺便说一句,你可能想知道使用'z'说明符可能的内存泄漏:http://thegothicparty.com/dev/article/nsdateformatter-memory-leak/ – 2010-09-14 19:48:27
+1使用“因此” – 2012-08-31 20:27:59