NSDateFormatter & #39; YYYY & #39; and & #39; yyyy & #39; nsdateformatter

Source: Internet
Author: User

Difference between NSDateFormatter 'yyyy' and 'yyyy', nsdateformatter

I saw this when I posted my microblog today:


Immediately, I thought of the bug that BK's feedback came back today. It was okay to run well for more than half a year. Today, I suddenly got a black screen. After debugging, I found that NSDateFormatter was in December 2015, today is July 22, 2014! Therefore, a problem occurs during the create preform operation.

After Google, it was discovered thatYYYYCaused by, change backYyyyThat's all. Specific differences:



After a simple test, I not only authenticated the question above, but also found another problem:

Let's take a look at the test:


It is correct to use [NSDate date] to obtain the current date: 00:42:25 CST (see the debug box on the left ), however, the output is a 16-hour difference between 16:42:25 and 0000 (look at the debug box on the right). It seems to be the time in the United States. After formatting the current time with @ "YYYY-MM-dd", the time difference is, which is one year different, this authentication indeed verifies that @ "YYYY-MM-dd" is calculated on a weekly basis.

For example, on October 28, 2014, there will be one year after the conversion, for example, 28,29, 30,31. On August 29, 2015, there will be one year after Sunday 27; sunday 2016 is the first day of June 2017, that is to say, the last day of weekly conversion calculation is the first day of the next year, so there will be no conversion errors; on Sunday 31, 2017, another year of change occurred .... Then we can see the clues. Let's think about it by yourself,Note: Remember to use the format @ "yyyy-MM-dd" to convert the date format in the future to avoid bugs derived from this situation.



Reference link:

Http://stackoverflow.com/questions/15133549/difference-between-yyyy-and-yyyy-in-nsdateformatter

Http://realmacsoftware.com/blog/working-with-date-and-time


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.