The first day of every year is 1st January and the last day is 31st December.
To get the first and last day of the current year, follow the following steps:
Date()
constructor and don't pass any arguments.getFullYear()
method.firstDay
, and lastDay
.let d = new Date(), currentYear = d.getFullYear(); let firstDay = new Date(currentYear, 0, 1); let lastDay = new Date(currentYear, 11, 31); console.log(firstDay.toString()); //Sat Jan 01 2022 console.log(lastDay.toString()); //Sat Dec 31 2022
You can also use the steps mentioned in this tutorial in React and Angular to get the first and last day of the year.
The Date
class follows zero-based numbering for months, which means January=0, February=1, March=2, ..., December=11.