【发布时间】:2010-09-14 19:18:16
【问题描述】:
我正在初始化我的 NSDateFormatter:
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”说明符可能存在的内存泄漏:thegothicparty.com/dev/article/nsdateformatter-memory-leak
标签: objective-c timezone nsdateformatter nstimezone