JavaScript - get today's date

9 points
Created by:

In this short article, we would like to show how to get today's Date in JavaScript.

Quick solution:

// ONLINE-RUNNER:browser;

const today = new Date();



Alternative solution

Using Date class we are able to get access to: year, month, day, hours, minutes, seconds, milliseconds, etc.

// ONLINE-RUNNER:browser;

const today = new Date();

console.log(today.getFullYear());      // todays' year, e.g. 2021
console.log(today.getMonth() + 1);     // todays' month (counted from 0 to 11)
console.log(today.getDate());          // todays' day (in the month)
console.log(today.getHours());         // current hour
console.log(today.getMinutes());       // current minutes
console.log(today.getSeconds());       // current seconds
console.log(today.getMilliseconds());  // current milliseconds


Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂