JS Date Object
Date object
The Date object is used to work with dates and times.
Create a Date object: new Date().
The following four methods also create a Date object:
var d = new Date();
var d = new Date(milliseconds);
var d = new Date(dateString);
var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
For a more complete Date tutorial, see JavaScript Date Objects tutorial.
Date object properties
Property | Description |
---|---|
constructor | Returns a reference to the Date function that created this object. |
prototype | Gives you the ability to add properties and methods to objects. |
Date object methods
Method | Description |
---|---|
getDate() | Returns the day of the month (1 through 31) from the Date object. |
getDay() | Returns the day of the week (0 to 6) from the Date object. |
getFullYear() | Returns the year as a four-digit number from the Date object. |
getHours() | Returns the hour (0 to 23) of the Date object. |
getMilliseconds() | Returns the milliseconds of the Date object (0 to 999). |
getMinutes() | Returns the minutes of the Date object (0 to 59). |
getMonth() | Returns the month (0 to 11) from the Date object. |
getSeconds() | Returns the number of seconds (0 to 59) of the Date object. |
getTime() | returns the number of milliseconds from january 1, 1970 to the present. |
getTimezoneOffset() | Returns the minute difference between local time and greenwich mean time (gmt). |
getUTCDate() | Returns the day of the month (1 through 31) from the Date object according to universal time. |
getUTCDay() | Returns the day of the week (0 to 6) from the Date object according to universal time. |
getUTCFullYear() | Returns a four-digit year from a Date object based on universal time. |
getUTCHours() | Returns the hour of the Date object (0 to 23) based on universal time. |
getUTCMilliseconds() | Returns the ms of the Date object according to universal time (0 ~ 999). |
getUTCMinutes() | Returns the minutes of the Date object (0 ~ 59) according to universal time. |
getUTCMonth() | Returns the month (0 to 11) from the Date object according to universal time. |
getUTCSeconds() | Returns the seconds (0 ~ 59) of the Date object according to universal time. |
getYear() | Deprecated. Use the getFullYear() method instead. |
parse() | Returns the number of milliseconds from midnight on january 1, 1970 to the specified date (string). |
setDate() | Sets the day of the month (1 to 31) in the Date object. |
setFullYear() | Sets the year (four digits) in the Date object. |
setHours() | Sets the hour (0 to 23) in the Date object. |
setMilliseconds() | Set the Date object in milliseconds (0 to 999). |
setMinutes() | Sets the minutes (0 to 59) in the Date object. |
setMonth() | Sets the month (0 to 11) in the Date object. |
setSeconds() | Sets the seconds (0 to 59) in the Date object. |
setTime() | The setTime() method sets the Date object in milliseconds. |
setUTCDate() | Sets the day of the month in the Date object (1 to 31) according to universal time. |
setUTCFullYear() | Sets the year (four digits) in the Date object according to universal time. |
setUTCHours() | Sets the hour (0 to 23) in the Date object according to universal time. |
setUTCMilliseconds() | Sets the ms in the Date object (0 to 999) according to universal time. |
setUTCMinutes() | Sets the minutes in the Date object (0 to 59) according to universal time. |
setUTCMonth() | Sets the month (0 to 11) in the Date object based on universal time. |
setUTCSeconds() | The setUTCSeconds() method is used to set the seconds field for a specified time based on Universal Time (UTC). |
setYear() | Deprecated. Use the setFullYear() method instead. |
toDateString() | Converts the date portion of a Date object to a string. |
toGMTString() | Deprecated. Use the toUTCString() method instead. |
toISOString() | Use the iso standard to return the date format of the string. |
toJSON() | Returns a date string in json data format. |
toLocaleDateString() | Converts the date portion of a Date object to a string based on the local time format. |
toLocaleTimeString() | Converts the time portion of the Date object to a string based on the local time format. |
toLocaleString() | Converts a Date object to a string based on the local time format. |
toString() | Converts the Date object to a string. |
toTimeString() | Converts the time portion of the Date object to a string. |
toUTCString() | Converts a Date object to a string based on universal time. Example: var today = new Date(); |
UTC() | Returns the number of milliseconds from january 1, 1970 to the specified date, based on universal time. |
valueOf() | Returns the original value of the Date object. |