IOS nsdateformatter Nslocale use En_us_posix or en_US

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.