2

我需要将一个 RESTful 放到服务器上。必须Date使用 like Sat, 19 Jan 2013 04:09:58 GMT

在objc中我写了这个:

NSDateFormatter* _GMTDateFormatter = [[NSDateFormatter alloc] init];
[_GMTDateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss"];
[_GMTDateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];

NSString* theDate = [_GMTDateFormatter stringFromDate:[NSDate date]];
theDate = [theDate stringByAppendingString:@" GMT"];
NSLog(@"%@",theDate);

它将被输出Sat, 19 Jan 2013 04:09:58 GMT

但在我的真实设备上,语言是中文,它会输出周六, 19 1月 2013 04:09:58 GMT

如何让它始终用英语?

4

1 回答 1

4

您需要设置NSDateFormatter对象的语言环境。

NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier: @"en_US"];
[_GMTDateFormatter setLocale: usLocale];
于 2013-01-19T04:33:58.687 回答