javascript
Get current year using Javascript Date getFullYear() method
To get the current year using javascript, you can use the .getFullYear() method of Date.
const today_date = new Date();
const current_year = today_date.getFullYear();
// -> returns the current year
In the above code snippet, we are getting current year from today's date. For this we are creating javascript Date object first and then using method getFullYear() to get the current date.
Live Demo
Was this helpful?
Similar Posts
- Get year from given date using Javascript
- Get the current month name using javascript
- Get month name from a date using javascript
- Convert all characters to lowercase using toLowerCase() method in javascript
- Add new item at first position of array using unshift() method Javascript
- Get current timestamp in javascript
- Remove all cookies from the current website using Javascript