Date.prototype.getTimezoneOffset
Returns the time zone offset in minutes.
Available since: ES1
Syntax
date.getTimezoneOffset()Return value
numberThe difference between UTC and local time in minutes.
Examples
The user's offset in hours:
const offset = new Date().getTimezoneOffset();
console.log(`UTC${offset <= 0 ? '+' : '-'}${Math.abs(offset) / 60}`);Output:
UTC+3Notes
The sign is reversed: for Berlin in winter (UTC+1) the method returns -60. The offset can change during the year because of daylight saving time, so call it on the date you need. The zone name comes from Intl.DateTimeFormat().resolvedOptions().timeZone.
See also
- Date.prototype.toISOString — Returns the date in ISO 8601 format in UTC.
- Date.prototype.toLocaleString — Formats a date together with the time by language rules.
In the tutorial
- Dates and time — The Date object in JavaScript: creating a date, reading the year, month and day, changing a date, the difference between dates and the ISO format.