这个时间戳本来是2015-12-27
但是打印出来是2016-12-27
时间戳:
1451145600
[formatter setDateFormat:@"YYYY-MM-dd"];
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
[formatter setTimeZone:timeZone];
[formatter stringFromDate:endDate]
PHP中文网2017-04-18 09:17:20
You should use lowercase yyyy instead of uppercase YYYY in your format string. Uppercase YYYY will format the year as the year in the ISO weekly calendar, which is the same most of the time, but the days at the end and beginning of the year may be different, see Wikipedia for details.
A common mistake is to use YYYY. yyyy specifies the calendar year whereas YYYY specifies the year (of “Week of Year”), used in the ISO year-week calendar. In most cases, yyyy and YYYY yield the same number, however they may be different. Typically you should use the calendar year.
refs: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW4