How to parsing NSDate to RFC 822 always use in English?

萝らか妹 提交于 2019-12-24 03:35:19

问题


I need to PUT a RESTful to server. the Date must use like Sat, 19 Jan 2013 04:09:58 GMT.

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);

it will be output Sat, 19 Jan 2013 04:09:58 GMT

but on my real device,the language is Chinese,it will output 周六, 19 1月 2013 04:09:58 GMT.

How to make it always use in English?


回答1:


You need to set the locale of the NSDateFormatter object.

NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier: @"en_US"];
[_GMTDateFormatter setLocale: usLocale];


来源:https://stackoverflow.com/questions/14411072/how-to-parsing-nsdate-to-rfc-822-always-use-in-english

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!