The date-time format object provided by the IOS SDK needs to use the Nslocale object to control the display of the date and time, and en_US is often used most of the standard formats, but friends who are accustomed to using Java or C # will overlook another format provided by the iOS SDK En_us_posix And the two formats work exactly the same way.
Reference code;
code is as follows |
copy code |
nsdateformatter *formatter1 = [[[NSDateFormatter alloc] init] autorelease]; [Formatter1 Setlocale:[[[nslocale alloc] initwithlocaleidentifier:@ "en_US"] autorelease]; NSDateFormatter *formatter2 = [[[NSDateFormatter alloc] init] autorelease]; [Formatter2 Setlocale:[[[nslocale alloc] initwithlocaleidentifier:@ "En_us_posix"] autorelease]; [formatter1 setdateformat:@ "Yyyy/mm/dd HH:mm:ss"]; [Formatter2 setdateformat:@ "Yyyy/mm/dd HH:mm:ss"]; NSDate *date = [NSDate date]; NSLog (@ "formatter1:%@", [Formatter1 stringfromdate:date]); NSLog (@ "formatter2:%@", [Formatter2 stringfromdate:date]); |
Using En_us_posix or en_US, Apple gives the answer in the SDK documentation.
The code is as follows |
Copy Code |
In most cases the best locale to choose is "En_us_posix" |
Because
"En_us_posix" is also invariant in time (if the US, at some point in the future, changes the way it formats dates, "en_US" 'll change to reflect the new behaviour, but "en_us_posix" won't), and between machines ("En_us_posix" works the same On the IPhone OS as it does on Mac OS X, and as it's it does on the other platforms).