EN
JavaScript - get today's date
9 points
In this short article, we would like to show how to get today's Date in JavaScript.
Quick solution:
xxxxxxxxxx
1
const today = new Date();
2
3
console.log(today);
Using Date
class we are able to get access to: year, month, day, hours, minutes, seconds, milliseconds, etc.
xxxxxxxxxx
1
const today = new Date();
2
3
console.log(today.getFullYear()); // todays' year, e.g. 2021
4
console.log(today.getMonth() + 1); // todays' month (counted from 0 to 11)
5
console.log(today.getDate()); // todays' day (in the month)
6
console.log(today.getHours()); // current hour
7
console.log(today.getMinutes()); // current minutes
8
console.log(today.getSeconds()); // current seconds
9
console.log(today.getMilliseconds()); // current milliseconds