What Is the Date Object?

This article describes the different methods for obtaining dates in various formats. The Date object in JavaScript returns a number representing milliseconds since midnight on January 1, 1970. Time is presented in Coordinated Universal Time (UTC) and isn't converted to time zones. When using the getDay() function, it uses local time from the computer. However, when using getUTCDay(), it returns UTC day instead of local time. The Date object is very useful when we need a timestamp or something similar.

Instance methods

Date.prototype.getDate()

Returns the day of the month (131) for the specified date according to local time.

Date.prototype.getDay()

Returns the day of the week (06) for the specified date according to local time.

Date.prototype.getFullYear()

Returns the year (4 digits for 4-digit years) of the specified date according to local time.

Date.prototype.getHours()

Returns the hour (023) in the specified date according to local time.

Date.prototype.getMilliseconds()

Returns the milliseconds (0999) in the specified date according to local time.

Date.prototype.getMinutes()

Returns the minutes (059) in the specified date according to local time.

Date.prototype.getMonth()

Returns the month (011) in the specified date according to local time.

Date.prototype.getSeconds()

Returns the seconds (059) in the specified date according to local time.

Date.prototype.getTime()

Returns the numeric value of the specified date as the number of milliseconds since January 1, 1970, 00:00:00 UTC. (Negative values are returned for prior times.)

Date.prototype.getTimezoneOffset()

Returns the time-zone offset in minutes for the current locale.

Date.prototype.getUTCDate()

Returns the day (date) of the month (131) in the specified date according to universal time.

Date.prototype.getUTCDay()

Returns the day of the week (06) in the specified date according to universal time.

Date.prototype.getUTCFullYear()

Returns the year (4 digits for 4-digit years) in the specified date according to universal time.

Date.prototype.getUTCHours()

Returns the hours (023) in the specified date according to universal time.

Date.prototype.getUTCMilliseconds()

Returns the milliseconds (0999) in the specified date according to universal time.

Date.prototype.getUTCMinutes()

Returns the minutes (059) in the specified date according to universal time.

Date.prototype.getUTCMonth()

Returns the month (011) in the specified date according to universal time.

Date.prototype.getUTCSeconds()

Returns the seconds (059) in the specified date according to universal time.

Date.prototype.getYear() Deprecated

Returns the year (usually 2–3 digits) in the specified date according to local time. Use getFullYear() instead.

Date.prototype.setDate()

Sets the day of the month for a specified date according to local time.

Date.prototype.setFullYear()

Sets the full year (e.g. 4 digits for 4-digit years) for a specified date according to local time.

Date.prototype.setHours()

Sets the hours for a specified date according to local time.

Date.prototype.setMilliseconds()

Sets the milliseconds for a specified date according to local time.

Date.prototype.setMinutes()

Sets the minutes for a specified date according to local time.

Date.prototype.setMonth()

Sets the month for a specified date according to local time.

Date.prototype.setSeconds()

Sets the seconds for a specified date according to local time.

Date.prototype.setTime()

Sets the Date object to the time represented by a number of milliseconds since January 1, 1970, 00:00:00 UTC. Use negative numbers for times prior.

Date.prototype.setUTCDate()

Sets the day of the month for a specified date according to universal time.

Date.prototype.setUTCFullYear()

Sets the full year (e.g. 4 digits for 4-digit years) for a specified date according to universal time.

Date.prototype.setUTCHours()

Sets the hour for a specified date according to universal time.

Date.prototype.setUTCMilliseconds()

Sets the milliseconds for a specified date according to universal time.

Date.prototype.setUTCMinutes()

Sets the minutes for a specified date according to universal time.

Date.prototype.setUTCMonth()

Sets the month for a specified date according to universal time.

Date.prototype.setUTCSeconds()

Sets the seconds for a specified date according to universal time.

Date.prototype.setYear() Deprecated

Sets the year (usually 2–3 digits) for a specified date according to local time. Use setFullYear() instead.

Date.prototype.toDateString()

Returns the "date" portion of the Date as a human-readable string like 'Thu Apr 12 2018'.

Date.prototype.toISOString()

Converts a date to a string following the ISO 8601 Extended Format.

Date.prototype.toJSON()

Returns a string representing the Date using toISOString(). Intended for use by JSON.stringify().

Date.prototype.toLocaleDateString()

Returns a string with a locality sensitive representation of the date portion of this date based on system settings.

Date.prototype.toLocaleString()

Returns a string with a locality-sensitive representation of this date. Overrides the Object.prototype.toLocaleString() method.

Date.prototype.toLocaleTimeString()

Returns a string with a locality-sensitive representation of the time portion of this date, based on system settings.

Date.prototype.toString()

Returns a string representing the specified Date object. Overrides the Object.prototype.toString() method.

Date.prototype.toTimeString()

Returns the "time" portion of the Date as a human-readable string.

Date.prototype.toUTCString()

Converts a date to a string using the UTC timezone.

Date.prototype.valueOf()

Returns the primitive value of a Date object. Overrides the Object.prototype.valueOf() method.

Date.prototype[@@toPrimitive]()

Converts this Date object to a primitive value.