2

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?

yellow
  • 702
  • 1
  • 10
  • 24

1 Answers1

4

You need to set the locale of the NSDateFormatter object.

NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier: @"en_US"];
[_GMTDateFormatter setLocale: usLocale];
adamkonrad
  • 6,794
  • 1
  • 34
  • 41
Richard Schneider
  • 34,944
  • 9
  • 57
  • 73