javascript – Print only the last two digits of a year

Question:

How to make the year have only two digits?

data = new Date().getFullYear();

console.log(data);

console.log(data.substr(2,4));

Answer:

We convert to string, then we just take the last two characters:

data = new Date().getFullYear().toString().substr(-2);
console.log(data);
Scroll to Top