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

前端 未结 1 944
情话喂你
情话喂你 2021-02-12 03:07

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

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-12 03:13

    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
    

    0 讨论(0)
提交回复
热议问题