ios - 神奇问题:时间戳转换成字符串 出现错误,只有15-12-27之后的错误。
大家讲道理
大家讲道理 2017-04-18 09:15:20
[iOS讨论组]


这个时间戳本来是2015-12-27
但是打印出来是2016-12-27

时间戳:
1451145600

[formatter setDateFormat:@"YYYY-MM-dd"];
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
[formatter setTimeZone:timeZone];
[formatter stringFromDate:endDate]
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(1)
PHP中文网

你的格式化字符串里应该用小写的 yyyy 而非大写的 YYYY。大写的 YYYY 会格式化年份为 ISO周日历 中的年份,大部分时候是相同的,但是在一年的年末和年初的几天就可能会不同,详见维基百科。

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号