iOS - Date Format Causes Year +1

19 In the last day of 12.31 days, my brother suddenly told me that the test time calculation problems, and I feel scared to go back and look at the code.

Since I need to convert the timestamp to a string with only a date, in order to compare whether two dates for the same day, so there is a problem

phenomenon:

 

 

 

currentDate go, strdate turn out, we found a year plus 1!

 

Proven and exclusion, compare wonderful find reasons: due date using the format YYYY-MM-dd, year uppercase, lowercase if it is normal

 

 

The reason is YYYY is calculated on a weekly basis, we usually best to use when calculating dates yyyy, yyyy is the mark of the year

Guess you like

Origin www.cnblogs.com/qzCodeDiary/p/12157831.html