HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
These methods can be used for getting information from a date object
The getTime()
method returns the number of milliseconds since January 1, 1970:
const d = new Date();
d.getTime();
The getFullYear()
method returns the year of a date as a four digit number:
const d = new Date();
d.getFullYear();
The getMonth()
method returns the month of a date as a number (0-11):
const d = new Date();
d.getMonth();
In JavaScript, the first month (January) is month number 0, so December returns month number 11.
You can use an array of names, and getMonth()
to return the month as a name:
const months = ["January", "February", "March", "April", "May",
"June", "July", "August", "September", "October",
"November", "December"];
const d = new Date();
let month = months[d.getMonth()];
The getDate()
method returns the day of a date as a number (1-31):
const d = new Date();
d.getDate();
The getHours()
method returns the hours of a date as a number (0-23):
const d = new Date();
d.getHours();
The getMinutes()
method returns the minutes of a date as a number (0-59):
const d = new Date();
d.getMinutes();
The getSeconds()
method returns the seconds of a date as a number (0-59):
const d = new Date();
d.getSeconds();
The getMilliseconds()
method returns the milliseconds of a date as a number (0-999):
const d = new Date();
d.getMilliseconds();
The getDay()
method returns the weekday of a date as a number (0-6):
const d = new Date();
d.getDay();
In JavaScript, the first day of the week (0) means "Sunday", even if some countries in the world consider the first day of the week to be "Monday"
You can use an array of names, and getDay()
to return the weekday as a name:
const days = ["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"];
const d = new Date();
let day = days[d.getDay()];
UTC date methods are used for working with UTC dates (Universal Time Zone dates):
Method | Description |
---|---|
getUTCDate() | Same as getDate(), but returns the UTC date |
getUTCDay() | Same as getDay(), but returns the UTC day |
getUTCFullYear() | Same as getFullYear(), but returns the UTC year |
getUTCHours() | Same as getHours(), but returns the UTC hour |
getUTCMilliseconds() | Same as getMilliseconds(), but returns the UTC milliseconds |
getUTCMinutes() | Same as getMinutes(), but returns the UTC minutes |
getUTCMonth() | Same as getMonth(), but returns the UTC month |
getUTCSeconds() | Same as getSeconds(), but returns the UTC seconds |
For a complete Date reference, go to our:
Complete JavaScript Date Reference.
The reference contains descriptions and examples of all Date properties and methods.
Use the correct Date method to get the month (0-11) out of a date object.
const d = new Date(); month = ;