Question

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?

Was it helpful?

Solution

You need to set the locale of the NSDateFormatter object.

NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier: @"en_US"];
[_GMTDateFormatter setLocale: usLocale];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top