How to get current year in JavaScript

Mahabubur Rahman
0

Using new Date() object we can get current year. 

Steps:

Get current date-time using new Date() object.

Get year from the object using getFullYear().

Example Code:

let date = new Date();

let year = date.getFullYear();

console.log(year);

Example Output:

2021


Post a Comment

0Comments
Post a Comment (0)