问题
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