Getting day of the current year in JavaScript

Let's get a date object containing March 8th of the current year. The words current year mean that the script should run in any year, always getting the year that is currently on the planet.

To do this, we need to make another helper object with a date containing the current moment in time. With this object, we can get the current year and then use that year to create an object with the date we want, like so:

let now = new Date(); // gets the current moment let date = new Date(now.getFullYear(), 2, 8); // gets our date

We can use the derived point in time, for example, to determine the day of the week corresponding to this date:


Determine what day of the week will be December 31 of the current year.