JavaScript的getYear()和getFullYear()函数有什么区别? [英] What's the difference between JavaScript's getYear() and getFullYear() functions?

查看:110
本文介绍了JavaScript的getYear()和getFullYear()函数有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JavaScript的 Date 对象,这是我第一次需要提取日期的年份部分。我所看到的是一种奇怪的行为。它返回 113 而非 2013 ,我无法弄清楚这两个数字之间的关系,除了最后两个数字可能相同。

I was working with JavaScript's Date object, and somewhere for the first time I needed to extract the year part of the date. What I saw was a weird behavior. It returns 113 instead of 2013 and I can't figure out how these two numbers might be related, except that the last two numbers might be the same.

var date = new Date();
console.log(date.getYear()); // prints 113
console.log(date.getFullYear()); // prints 2013

这些功能有何不同?为什么有一个函数 getFullYear
我得到部分一年是没有意义的。

How these functions are different? And why having a function to getFullYear? It just makes no sense to me to get part of a year.

推荐答案


我对一年中的部分时间没有任何意义。

It just makes no sense to me to get part of a year.

回到当天,当时记忆是昂贵的,而2000年是遥远的未来,人们有理由将1975年代表为75.回想起一个短视的决定。

Back in the day, when memory was expensive and the Year 2000 was far in the future, it did make sense for people to represent 1975 as 75. In retrospect a short-sighted decision.

date.getFullYear() == date.getYear() + 1900

这篇关于JavaScript的getYear()和getFullYear()函数有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆