getters
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.
date.getTimezoneOffset() Parameters
| Parameter | Purpose |
|---|---|
| () | no arguments; returns Number (minutes) |
| sign | negative for zones ahead of UTC, positive for zones behind |
| DST | varies by date within a zone (summer vs winter) |
Examples
// In India (UTC+05:30)
console.log(new Date().getTimezoneOffset()); // -330 sign is reversed
// In New York EST (UTC-05:00)
console.log(new Date('2026-01-15').getTimezoneOffset()); // 300 west of UTC = positive
const off = new Date().getTimezoneOffset(); console.log(`${-off/60} hours from UTC`); convert to hours with correct sign
Gotcha
The sign is INVERSE to what most humans call the offset (UTC+05:30 -> -330). Multiply by -1 to get a normal offset in minutes.
Related
Date.prototype.getUTCFullYear / getUTCMonth / getUTCDate / getUTCHours
The UTC-flavored getters mirror their local counterparts but read fields in Coordinated Universal Time, ignoring the host timezone. Use them whenever you need timezone-stable output such as logs, database keys, or ISO output.
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.
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.
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.