JS: Date.prototype

By Xah Lee. Date: . Last updated: .

What is Date.prototype

Date.prototype is the value of the property key "prototype" of the function Date. 〔see Date Object

console.assert((Object.hasOwn(Date, "prototype")) === true);

Type

Type of Date.prototype is Object .

console.assert(typeof Date.prototype === "object");

Parent

Parent of Date.prototype is Object.prototype .

console.assert(Reflect.getPrototypeOf(Date.prototype) === Object.prototype);

Purpose

Date.prototype is the parent of all date objects.

console.assert(Reflect.getPrototypeOf(new Date()) === Date.prototype);

Purpose of Date.prototype is to provide methods and properties useful for all date objects.

Properties

Date Object Get Methods

Most date get methods have 2 versions. One returns local time info, one returns UTC time info. e.g. getHours() for local, and getUTCHours(). The UTC version return the UTC representation.

// example of using Date get methods

const xdd = new Date("2017-06-13T21:00:01.000Z");

// milliseconds
console.assert(xdd.getTime() === 1497387601000);

console.assert(xdd.getFullYear() === 2017);
console.assert(xdd.getMonth() === 5); // warning: jan is 0.
console.assert(xdd.getDate() === 13);
console.assert(xdd.getDay() === 2);
console.assert(xdd.getHours() === 14);
console.assert(xdd.getMinutes() === 0);
console.assert(xdd.getSeconds() === 1);

console.assert(xdd.getUTCMonth() === 5); // warning: jan is 0.
console.assert(xdd.getUTCDate() === 13);
console.assert(xdd.getUTCDay() === 2);
console.assert(xdd.getUTCHours() === 21);
console.assert(xdd.getUTCMinutes() === 0);
console.assert(xdd.getUTCSeconds() === 1);
getTime()

Return the millisecond representation of a Date object. Sample: 1428605303481.

getFullYear()

Year of the date. 4 digits. e.g. 2014.

getYear()

Return the year minus 1901. Deprecated. Use getFullYear().

getMonth()

Month. 0 to 11. January is 0.

getDate()

Day of the month. 1 to 31.

getDay()

Day of the week. 0 to 6. Sunday is 0. Monday is 1. Saturday is 6.

getHours()

Hours. 0 to 23.

getMinutes()

Minutes. 0 to 59.

getSeconds()

Seconds. 0 to 59.

getMilliseconds()

Milliseconds field of a Date object. 0 to 999.

getTimezoneOffset()

Difference, in minutes, between the local and UTC time of this date. Daylight saving time is taken account of.

Date Object Set Methods

You can also set a date object's year, month, or any of the parts.

const xdate = new Date("2017-04-08T06:00:10.000Z");

console.log(xdate);
// 2017-04-08T06:00:10.000Z

xdate.setMinutes(30);

console.log(xdate);
// 2017-04-08T06:30:10.000Z
setTime(milliseconds)

Set the date object to a specific datetime of milliseconds, the internal date format.

setFullYear(year, month, date)

Set the year to year. The other parameters are optional.

setYear(year)

Set the year to year. Deprecated. Use setFullYear().

setMonth(month, date)

Set the month to month. Note, January is 0. Other parameters are optional.

setDate(date)

Set the date part to date.

setHours(hour, min, sec, millisecond)

Set the hour to hour. The rest parameters are optional.

setMinutes(min, sec, millisecond)

Set the minutes to min. The rest parameters are optional.

setSeconds(sec, millisecond)

Set the second sec. The rest parameters are optional.

setMilliseconds(ms)

Set the milliseconds part of a date to ms.

UTC versions of get and set

Most date get/set methods have 2 versions. One returns local time info, one returns UTC time info. e.g. getHours() vs getUTCHours().

  • getUTCFullYear()
  • getUTCMonth()
  • getUTCDate()
  • getUTCDay()
  • getUTCHours()
  • getUTCMinutes()
  • getUTCSeconds()
  • getUTCMilliseconds()
  • setUTCFullYear()
  • setUTCMonth()
  • setUTCDate()
  • setUTCHours()
  • setUTCMinutes()
  • setUTCSeconds()
  • setUTCMilliseconds()

Print

// date methods for to string.

console.log((new Date()).toLocaleString());
// 2/3/2026, 10:13:50 PM

console.log((new Date()).toLocaleDateString());
// 2/3/2026

console.log((new Date()).toLocaleTimeString());
// 10:14:35 PM

console.log((new Date()).toDateString());
// Tue Feb 03 2026

console.log((new Date()).toTimeString());
// 22:15:03 GMT-0800 (Pacific Standard Time)

console.log((new Date()).toISOString());
// 2026-02-04T06:15:14.346Z

console.log((new Date()).toUTCString());
// Wed, 04 Feb 2026 06:15:24 GMT

// deprecated
console.log((new Date()).toGMTString());
// Wed, 04 Feb 2026 06:15:38 GMT

// basically same as toISOString
console.log((new Date()).toJSON());
// 2026-02-04T06:15:54.343Z

console.log((new Date()).toString());
// Tue Feb 03 2026 22:16:12 GMT-0800 (Pacific Standard Time)

// same as getTime
console.log((new Date()).valueOf());
// 1770185784233

Misc

Date.prototype.constructor
Date.prototype[Symbol.toPrimitive] (new in ECMAScript 2015)

JavaScript. Date