The JavaScript Date object is used to create objects that store all the temporal values of a point in time, from its year to its millisecond. The methods of this object provide a great variety of ways to set and obtain values from that point in time.
Constructors
You can create a new Date object using the constructor of the Date object in four different ways:
var myDate = new Date() /* Creates a new Date object specifying its point in time as the one of its creation. */
var myDate = new Date(milliseconds) /* Creates a new Date object specifying its point in time in milliseconds passed since January 1st 1970. */
var myDate = new Date(dateString) /* Creates a new Date object specifying its point in time by the information in a string. There are various possible patterns for the dateString string. */
var myDate = new Date(year, month, day of the month, hours, minutes, seconds, milliseconds) /* Creates a new Date Object specifying the temporal values of its point in time. All the parameters are numbers and the month must be a number from 0 to 11, zero being January and eleven being December. Only the year, the month, and the day of the month are required; the rest are optional. */
var myDate = new Date(milliseconds) /* Creates a new Date object specifying its point in time in milliseconds passed since January 1st 1970. */
var myDate = new Date(dateString) /* Creates a new Date object specifying its point in time by the information in a string. There are various possible patterns for the dateString string. */
var myDate = new Date(year, month, day of the month, hours, minutes, seconds, milliseconds) /* Creates a new Date Object specifying the temporal values of its point in time. All the parameters are numbers and the month must be a number from 0 to 11, zero being January and eleven being December. Only the year, the month, and the day of the month are required; the rest are optional. */
Methods
getDate | Returns the day of the month of the stored point in time in an integer number from 1 to 31. |
getDay | Returns the day of the week of the stored point in time in a number from 0 to 6, zero being Sunday and six being Saturday. |
getFullYear | Returns the year of the stored point in time with all its digits. |
getHours | Returns the hour of the stored point in time in a number from 0 to 23. |
getMilliseconds | Returns the milliseconds since the last second of the stored point in time in a number from 0 to 999. |
getMinutes | Returns the minutes of the stored point in time in a number from 0 to 59. |
getMonth | Returns the month of the stored point in time in a number from 0 to 11, zero being January and eleven being December. |
getSeconds | Returns the seconds of the stored point in time in a number from 0 to 59. |
getTime | Returns the quantity of milliseconds passed since January 1st 1970 until the stored point in time. |
getTimezoneOffset | Returns the difference in minutes between the universal time and the time in the host computer. |
getUTCDate | Returns the day of the month of the stored point in time according to universal time in a number from 1 to 31. |
getUTCDay | Returns the day of the week of the stored point in time according to universal time in a number from 0 to 6, zero being Sunday and six being Saturday. |
getUTCFullYear | Returns the year of the stored point in time with all its digits according to universal time. |
getUTCHours | Returns the hour of the stored point in time according to universal time in a number from 0 to 23. |
getUTCMilliseconds | Returns the milliseconds of the stored point in time according to universal time in a number from 0 to 999. |
getUTCMinutes | Returns the minutes of the stored point in time according to universal time in a number from 0 to 59. |
getUTCMonth | Returns the month of the stored point in time according to universal time in a number from 0 to 11, zero being January and eleven being December. |
getUTCSeconds | Returns the seconds of the stored point in time according to universal time in a number from 0 to 59. |
getYear | Deprecated. ¡Don't use it! It used to return the last two digits of a year but now it works in different ways in different browsers. The right way to get the year is with getFullYear. |
setDate | Sets the day of the month of the point in time stored in the Date object. |
setFullYear | Sets the year of the point in time stored in the Date object. |
setHours | Sets the hour of the point in time stored in the Date object. |
setMilliseconds | Sets the milliseconds of the point in time stored in the Date object. |
setMinutes | Sets the minutes of the point in time stored in the Date object. |
setMonth | Sets the month value of the point in time stored in the Date object. |
setSeconds | Sets the seconds value of the point in time stored in the Date object. |
setTime | Sets a point in time by the quantity of milliseconds passed since midnight January 1st 1970 universal time. |
setUTCDate | Sets the day of the month value of the point in time stored in the Date object according to universal time. |
setUTCFullYear | Sets the year value of the point in time stored in the Date object according to universal time. |
setUTCHours | Sets the hour value of the point in time stored in the Date object according to universal time. |
setUTCMilliseconds | Sets the milliseconds value of the point in time stored in the Date object according to universal time. |
setUTCMinutes | Sets the minutes value of the point in time stored in the Date object according to universal time. |
setUTCMonth | Sets the month value of the point in time stored in the Date object according to universal time. |
setUTCSeconds | Sets the seconds value of the point in time stored in the Date object according to universal time. |
setYear | Deprecated. ¡Don't use it! Use the setFullYear method instead. |
toDateString | Returns as a readable string the date of the point in time stored in the Date object. |
toGMTString | Deprecated. ¡Don't use it! Use the toUTCString method instead. |
toISOString | Returns as a readable string that complies with the ISO standard the date of the point in time stored in the Date object. |
toJSON | Returns as a readable string that complies with the JSON standard the date of the point in time stored in the Date object. |
toLocaleDateString | Returns as a readable string that complies with the local conventions the date of the point in time stored in the Date object. |
toLocaleTimeString | Returns as a readable string that complies with the local conventions the time of the point in time stored in the Date object. |
toLocaleString | Returns as a readable string that complies with the local conventions both date and time of the point in time stored in the Date object. |
toString | Returns a string containing the date and time of the point in time stored in a Date object. |
toTimeString | Returns as a readable string the time of the point in time stored in the Date object. |
toUTCString | Returns as a readable string in universal time both date and time of the point in stored in the Date object. |
valueOf | Returns the quantity of milliseconds passed since midnight January 1st 1970 universal time until the stored point in time. |
Date Static Methods:
Date.now | Returns the quantity of milliseconds between January 1st 1970 and the current point in time. |
Date.parse | Parses a string that contains a date and time and returns the quantity of milliseconds passed since midnight January 1st 1970 until the point in time of the string. |
Date.UTC | Returns, for the provided date, the quantity of milliseconds passed since midnight January 1st 1970 universal time. |
JavaScript Manual >> Date Object