Categories
JavaScript Answers

How to fix JavaScript date.getYear() returning 111 in 2011?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *