JavaScript Date Reference
Every Date method — including the classic getMonth 0-indexed
gotcha, timezone-offset sign trap, and the modern Intl.DateTimeFormat.
Constructor & Static
new Date()
Creates a Date object representing a single moment in time as milliseconds since the Unix epoch (1970-01-01T00:00:00Z). Called with no arguments it returns the current instant; with arguments it parses a timestamp, ISO string, or component parts.
Date.now
Returns the current time as an integer number of milliseconds since the Unix epoch without allocating a Date object. Use it for timestamps, expiry checks, and simple timing.
Date.UTC
Returns the milliseconds since the Unix epoch for the given components interpreted as UTC. Unlike the Date component constructor, it does not apply the local timezone.
Getters
Date.prototype.getFullYear
Returns the 4-digit year of the date according to LOCAL time. Prefer this over the deprecated getYear(), which returns year-1900.
Date.prototype.getMonth
Returns the month of the date in LOCAL time as an integer from 0 (January) to 11 (December). This zero-based indexing is the single most common source of off-by-one date bugs in JavaScript.
Date.prototype.getDate
Returns the day of the month (1-31) in LOCAL time. Do not confuse this with getDay, which returns the weekday.
Date.prototype.getDay
Returns the weekday of the date in LOCAL time as an integer from 0 (Sunday) to 6 (Saturday). Named confusingly close to getDate but returns something completely different.
Date.prototype.getHours
Returns the hour of the date in LOCAL time as an integer from 0 to 23. Companion methods getMinutes, getSeconds, and getMilliseconds work the same way for their respective units.
Date.prototype.getMinutes
Returns the minutes portion of the date in LOCAL time as an integer from 0 to 59. The identically shaped getSeconds (0-59) and getMilliseconds (0-999) round out the sub-hour getters.
Date.prototype.getTime
Returns the underlying timestamp of the date as milliseconds since the Unix epoch (1970-01-01T00:00:00Z). This is the canonical way to compare, subtract, or serialize a Date as a number.
Date.prototype.getTimezoneOffset
Returns the difference between UTC and the host's local time in MINUTES with the SIGN REVERSED from the conventional offset. So India (UTC+05:30) returns -330 and New York in EST (UTC-05:00) returns 300.
Setters
Formatting
Date.prototype.toISOString
Returns the date as an ISO 8601 extended-format string in UTC, always ending in 'Z'. This is the canonical machine-readable serialization and the format most APIs and databases accept.
Date.prototype.toJSON
Returns an ISO 8601 UTC string suitable for JSON serialization; called automatically by JSON.stringify when it encounters a Date. Equivalent to toISOString() for valid dates, but returns null for Invalid Dates instead of throwing.
Date.prototype.toLocaleDateString
Returns the date portion formatted for a given locale and options, without the time. For repeated formatting, cache an Intl.DateTimeFormat instead - it is significantly faster.
Date.prototype.toLocaleTimeString
Returns the time portion formatted for a given locale and options, without the date. Same locale/options rules as toLocaleDateString.
Date.prototype.toLocaleString
Returns date and time together formatted for a given locale. Accepts the union of date and time options from Intl.DateTimeFormat.
Date.prototype.toDateString
Returns the date portion of the Date as a fixed English string, e.g. 'Sun Jul 19 2026'. Companion to toTimeString which returns something like '15:30:00 GMT+0530 (India Standard Time)'.
Date.prototype.toUTCString
Returns the date as a string in the older RFC 7231 / IMF-fixdate format, e.g. 'Sun, 19 Jul 2026 00:00:00 GMT'. This is the exact format required by HTTP headers like Date, Expires, and cookies.
Date.prototype.toString
Returns a fixed English representation of the date in LOCAL time, e.g. 'Sun Jul 19 2026 05:30:00 GMT+0530 (India Standard Time)'. Called implicitly by template literals and string concatenation.
Parsing
UTC Variants
Intl (Internationalization)
Intl.DateTimeFormat
The modern locale-aware date/time formatter, preferred over toLocaleString for repeated formatting because you can construct the formatter once and reuse it. Also offers formatToParts, formatRange, and formatRangeToParts for finer control and internationalized date ranges.
Intl.RelativeTimeFormat
Formats relative times such as '3 days ago' or 'in 2 hours' in a locale-aware way, replacing hand-rolled 'time ago' helpers. Combine it with a small diff-and-pick-unit function to render human-friendly relative timestamps.