
这个时间戳本来是2015-12-27
但是打印出来是2016-12-27
时间戳:
1451145600
[formatter setDateFormat:@"YYYY-MM-dd"];
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
[formatter setTimeZone:timeZone];
[formatter stringFromDate:endDate]
                            
                                    Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你的格式化字符串里应该用小写的 yyyy 而非大写的 YYYY。大写的 YYYY 会格式化年份为 ISO周日历 中的年份,大部分时候是相同的,但是在一年的年末和年初的几天就可能会不同,详见维基百科。
refs:https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW4