Date

A JavaScript date is specified as the number of milliseconds that have elapsed since midnight on January 1, 1970, UTC. Maximum value is ±100_000_000 days.

constructors

There are several constructors.

  1. An empty constructor creates a Date object with the current date and time.
  2. A constructor with explicitly set milliseconds since midnight on January 1, 1970, UTC.
  3. A constructor with string value representing a date, specified in a format recognized by the Date.parse() method.
  4. A constructor with date and time component values.
    The year component represents by integer value. Values from 0 to 99 map to the years 1900 to 1999. All other values are the actual year.
    The month component represents by integer value in range [0; 11], where 0 is January, 11 is December.
    The day component is represented by an integer value in the range [1; 31]. The default value is 1.
    All other components represents by integer value in usual way. Default value is 0.
/* 
Date() - empty constructor
Date(value) - constructor by time value
Date(dateString) - constructor by date string
Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]]]]])
*/

static methods

methods description
now() Returns the numeric value corresponding to the current time.
parse(str) Attempts to parse a given string in ISO 8601 format. For example, "2020-12-10T112: 30: 00,000 + 09: 00". Parsing other formats depends on the browser.
UTC(...) Same as Date constructor with components of time. But since ECMAScript 2017 the month component is optional parameter.

methods

methods description
getDate() Returns the day of the month (1–31) for the specified date according to local time.
getDay() Returns the day of the week (0–6) for the specified date according to local time.
getFullYear() Returns the year (4 digits for 4-digit years) of the specified date according to local time.
getHours() Returns the hour (0–23) in the specified date according to local time.
getMilliseconds() Returns the milliseconds (0–999) in the specified date according to local time.
getMinutes() Returns the minutes (0–59) in the specified date according to local time.
getMonth() Returns the month (0–11) in the specified date according to local time.
getSeconds() Returns the seconds (0–59) in the specified date according to local time.
getTime() Returns the number of milliseconds since January 1, 1970, 00:00:00 UTC. Negative values are possible for prior times.
getTimezoneOffset() Returns the time-zone offset in minutes for the current locale.
getUTCDate() Returns the day of the month (1–31) in the specified date according to universal time.
getUTCDay() Returns the day of the week (0–6) in the specified date according to universal time.
getUTCFullYear() Returns the year (4 digits for 4-digit years) in the specified date according to universal time.
getUTCHours() Returns the hours (0–23) in the specified date according to universal time.
getUTCMilliseconds() Returns the milliseconds (0–999) in the specified date according to universal time.
getUTCMinutes() Returns the minutes (0–59) in the specified date according to universal time.
getUTCMonth() Returns the month (0–11) in the specified date according to universal time.
getUTCMinutes() Returns the minutes (0–59) in the specified date according to universal time.
getUTCMonth() Returns the month (0–11) in the specified date according to universal time.
getUTCSeconds() Returns the seconds (0–59) in the specified date according to universal time.
getYear() Returns the year (usually 2–3 digits) in the specified date according to local time.
setDate(day) Sets the day of the month for a specified date according to local time.
setFullYear(day) Sets the full year (e.g. 4 digits for 4-digit years) for a specified date according to local time.
setHours(h) Sets the hours for a specified date according to local time.
setMilliseconds(ms) Sets the milliseconds for a specified date according to local time.
setMinutes(m) Sets the minutes for a specified date according to local time.
setMonth(M) Sets the month for a specified date according to local time.
setSeconds(s) Sets the seconds for a specified date according to local time.
setTime(ms) 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.
setUTCDate(day) Sets the day of the month for a specified date according to universal time.
setUTCFullYear(y) Sets the full year (e.g. 4 digits for 4-digit years) for a specified date according to universal time.
setUTCHours(h) Sets the hour for a specified date according to universal time.
setUTCMilliseconds(ms) Sets the milliseconds for a specified date according to universal time.
setUTCMinutes(m) Sets the minutes for a specified date according to universal time.
setUTCMonth(M) Sets the month for a specified date according to universal time.
setUTCSeconds(s) Sets the seconds for a specified date according to universal time.
setYear(y) Sets the year (usually 2–3 digits) for a specified date according to local time.
toDateString() Returnsa human-readable string like 'Thu Apr 28 1978'.
toISOString() Returns a date string in the ISO 8601 format.
toJSON() Returns a string representing the Date using toISOString(). Intended for use by JSON.stringify().
toLocaleDateString() Returns a string with a language sensitive representation of the date.
toString() Returns a string representing the specified Date object.
valueOf() Returns the primitive value of a Date object.