JavaScript Date Methods
JavaScript Date Methods
w3schools.com LOG IN
These methods can be used for getting information from a date object:
Method Description
The getTime() method returns the number of milliseconds since January 1, 1970:
Example
var d = new Date();
document.getElementById("demo").innerHTML = d.getTime();
Try it Yourself »
Example
Try it Yourself »
https://www.w3schools.com/js/js_date_methods.asp 2/11
1/16/2021 JavaScript Date Methods
Example
Try it Yourself »
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:
Example
var d = new Date();
var months = ["January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"];
document.getElementById("demo").innerHTML = months[d.getMonth()];
Try it Yourself »
https://www.w3schools.com/js/js_date_methods.asp 3/11
1/16/2021 JavaScript Date Methods
Example
var d = new Date();
document.getElementById("demo").innerHTML = d.getDate();
Try it Yourself »
Example
var d = new Date();
document.getElementById("demo").innerHTML = d.getHours();
Try it Yourself »
Example
var d = new Date();
document.getElementById("demo").innerHTML = d.getMinutes();
Try it Yourself »
https://www.w3schools.com/js/js_date_methods.asp 4/11
1/16/2021 JavaScript Date Methods
Example
var d = new Date();
document.getElementById("demo").innerHTML = d.getSeconds();
Try it Yourself »
Example
var d = new Date();
document.getElementById("demo").innerHTML = d.getMilliseconds();
Try it Yourself »
Example
https://www.w3schools.com/js/js_date_methods.asp 5/11
1/16/2021 JavaScript Date Methods
Try it Yourself »
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:
Example
var d = new Date();
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday"];
document.getElementById("demo").innerHTML = days[d.getDay()];
Try it Yourself »
Method Description
The reference contains descriptions and examples of all Date properties and methods.
Exercise:
Use the correct Date method to get the month (0-11) out of a date object.
Submit Answer »
❮ Previous Next ❯
https://www.w3schools.com/js/js_date_methods.asp 7/11