What's the difference between JavaScript's getYear() and getFullYear() functions?

前端 未结 3 1447
臣服心动
臣服心动 2021-02-12 02:52

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 re

3条回答
  •  既然无缘
    2021-02-12 03:17

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

    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
    

提交回复
热议问题