getFullYear() method on
new Date() constructor and subtract it with
getFullYear()method returns the current year in four-digit(2020) format according to the user local time.
Here is an example:
const currentYear = new Date().getFullYear(); // 2020 const previousYear = currentYear-1; console.log(previousYear); // 2019
If you want to set a previous year to the current date, you can do it like this:
const d = new Date(); d.setFullYear(d.getFullYear()-1); console.log(d.toDateString()); // "Fri Oct 04 2019"