javascript - date对象获取年的问题
大家讲道理
大家讲道理 2017-04-10 18:01:42
[JavaScript讨论组]

getTime() 返回从 1970 年 1 月 1 日至今的毫秒数,那么我用这个获取年为什么是+1900而不是+1970呢?var year=d.getYear()+1900;

大家讲道理
大家讲道理

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

全部回复(2)
迷茫

请用 getFullYear()

getyear() 被废弃 参考:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date/getYear

Return Value:
For years greater than or equal to 2000, the value returned by getYear is 100 or greater. For example, if the year is 2026, getYear returns 126.
For years between and including 1900 and 1999, the value returned by getYear is between 0 and 99. For example, if the year is 1976, getYear returns 76.
For years less than 1900, the value returned by getYear is less than 0. For example, if the year is 1800, getYear returns -100.
迷茫
date.getFullYear()
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

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