如何将 NSDate 解析为 RFC 822 始终使用英文? [英] How to parsing NSDate to RFC 822 always use in English?
本文介绍了如何将 NSDate 解析为 RFC 822 始终使用英文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将 RESTful 放到服务器上.Date
必须像 Sat, 19 Jan 2013 04:09:58 GMT
一样使用.
I need to PUT a RESTful to server.
the Date
must use like Sat, 19 Jan 2013 04:09:58 GMT
.
在 objc 中我写了这个:
in objc I wrote this:
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
但在我的真机上,语言是中文,它会输出周六,2013年1月19日04:09:58 GMT
.
but on my real device,the language is Chinese,it will output 周六, 19 1月 2013 04:09:58 GMT
.
如何让它一直用英文?
推荐答案
您需要设置 NSDateFormatter
对象的语言环境.
You need to set the locale of the NSDateFormatter
object.
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier: @"en_US"];
[_GMTDateFormatter setLocale: usLocale];
这篇关于如何将 NSDate 解析为 RFC 822 始终使用英文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文