⊗jsPmTmMDCY 325 of 504 menu

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:

console.log(date.getDay());

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

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline