This site is mobile accessible. Press the "Tap Here" button to use a different font-size.
Smartphone icons created by Freepik - Flaticon
These methods can be used for getting information from a date object:
Method | Description |
---|---|
getFullYear() | Get the year as a four digit number (yyyy) |
getMonth() | Get the month as a number (0-11) |
getDate() | Get the day as a number (1-31) |
getHours() | Get the hour (0-23) |
getMinutes() | Get the minute (0-59) |
getSeconds() | Get the second (0-59) |
getMilliseconds() | Get the millisecond (0-999) |
getTime() | Get the time (milliseconds since January 1, 1970) |
getDay() | Get the weekday as a number (0-6) |
Date.now() | Get the time. ECMAScript 5. |
The
method returns the number of milliseconds since January 1, 1970:var d = new Date(); document.getElementById("demo").innerHTML = d.getTime();
The
method returns the year of a date as a four digit number:var d = new Date(); document.getElementById("demo").innerHTML = d.getFullYear();
The
method returns the month of a date as a number (0-11):var d = new Date(); document.getElementById("demo").innerHTML = 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
to return the month as a name: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()];
The getDate() method returns the day of a date as a number (1-31):
var d = new Date(); document.getElementById("demo").innerHTML = d.getDate();
The
method returns the hours of a date as a number (0-23):var d = new Date(); document.getElementById("demo").innerHTML = d.getHours();
The
method returns the minutes of a date as a number (0-59):var d = new Date(); document.getElementById("demo").innerHTML = d.getMinutes();
The
method returns the seconds of a date as a number (0-59):var d = new Date(); document.getElementById("demo").innerHTML = d.getSeconds();
The
method returns the milliseconds of a date as a number (0-999):var d = new Date(); document.getElementById("demo").innerHTML = d.getMilliseconds();
The getDay() method returns the weekday of a date as a number (0-6):
var d = new Date(); document.getElementById("demo").innerHTML = d.getDay();
var d = new Date(); var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; document.getElementById("demo").innerHTML = 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 |
Eventually the navigation links, above, will be replaced by these (previous) and (next) buttons below.
JavaScript icons used in the buttons provided by ICONS8.COM. Smartphone icons created by Freepik - Flaticon