How to determine one year from now in JavaScript?

Sometimes, we want to determine one year from now in JavaScript.

In this article, we’ll look at how to determine one year from now in JavaScript.

How to determine one year from now in JavaScript?

To determine one year from now in JavaScript, we call the getFullYear and setFullYear method.

For instance, we write

const d = new Date(new Date().setFullYear(new Date().getFullYear() + 1));

to get the 4 digit year of the current date time with

new Date().getFullYear()

Then we add 1 to it and call setFullYear with the sum to set the date to be 1 year from now.

And create a new Date object with the same date time by using Date with

new Date().setFullYear(new Date().getFullYear() + 1)

Conclusion

To determine one year from now in JavaScript, we call the getFullYear and setFullYear method.