Sometimes, we want to fix JavaScript date.getYear() returning 111 in 2011.
In this article, we’ll look at how to fix JavaScript date.getYear() returning 111 in 2011.
How to fix JavaScript date.getYear() returning 111 in 2011?
To fix JavaScript date.getYear() returning 111 in 2011, we replace getYear
with getFullYear
.
For instance, we write
const y = new Date().getFullYear();
to get the 4 digit year of the current date with getFullYear
.
Conclusion
To fix JavaScript date.getYear() returning 111 in 2011, we replace getYear
with getFullYear
.