In IOS development, I ran into strange problems.
[dateformatterstringfromdate:adate];
Dateformatter is a NSDateFormatter object.
Adate is a NSDate object with a value of 2015-12-30 00:00.
This code is to convert this nsdate into NSString.
The result I got was amazing: "2016-12-30 00:00"!!!
Again, this time the value of the NSDate object is changed to 2017-12-30 00:00.
The result is: "2017-12-30 00:00".
I'm crazy to see this, isn't Apple's code so obviously wrong?
After a period of testing and online search, finally found the reason.
There was an error in the formatting of the NSDateFormatter object.
I am using "yyyy-mm-dd". Change to "Yyyy-mm-dd". Problem Solving!!!
So what's the difference between YYYY and YYYY? YYYY is the standard year, while YYYY is the year of the ISO Year-week calendar.
Reference Links:
Http://stackoverflow.com/questions/15133549/difference-between-yyyy-and-yyyy-in-nsdateformatter
Http://stackoverflow.com/questions/12423179/nsdateformatter-show-wrong-year
Date format, do you use the right one?