本文介绍了为什么Javascript getYear()返回108?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么这个javascript返回108而不是2008?它得到日期和月份正确但不是一年? myDate = new Date();
year = myDate.getYear();
year = 108?
解决方案
这是一个的事情,只有从1900年开始计算。
现在有一些潜在的兼容性问题, getYear()
已被弃用,有利于 getFullYear()
- 从:
*根据getYear()的年份:108
*根据getFullYear()的年份:2008
Internet Explorer和Firefox之间也有实现差异,因为IE的 getYear()
的实现已更改为表现得像 getFullYear()
- 从:
Why does this javascript return 108 instead of 2008? it gets the day and month correct but not the year?
myDate = new Date();
year = myDate.getYear();
year = 108?
解决方案
It's a Y2K thing, only the years since 1900 are counted.
There are potential compatibility issues now that getYear()
has been deprecated in favour of getFullYear()
- from quirksmode:
* The year according to getYear(): 108
* The year according to getFullYear(): 2008
There are also implementation differences between Internet Explorer and Firefox, as IE's implementation of getYear()
was changed to behave like getFullYear()
- from IBM:
这篇关于为什么Javascript getYear()返回108?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!