JavaScript Reference ยท Date and Intl
Date.prototype.getTimezoneOffset()
Reference for JavaScript getTimezoneOffset(): get the difference between UTC and local time in minutes, understand the inverted sign and handle daylight saving.
getTimezoneOffset() returns the difference, in minutes, between UTC and the local time of the device for a given date. It is the number you would add to the local time to get UTC.
The sign is the opposite of what most people expect. Places east of UTC (Berlin, Tokyo) give a negative number, and places west (New York, Los Angeles) give a positive one. UTC itself gives 0.
// In Berlin in winter: -60 // In New York in winter: 300 new Date().getTimezoneOffset();
Try it
Press Run (or Ctrl + Enter) to see the console output here.
No output.
Press Run (or Ctrl + Enter) to see the console output here.
No output.
Syntax
date.getTimezoneOffset()
Parameters: none.
Return value: the offset in minutes, as UTC minus local time (so UTC+2 is -120). It is NaN for an invalid date. It may be fractional for historical dates, and many places have offsets that are not whole hours, such as -330 for India.
Exceptions: none.
Usage notes
- The sign is inverted compared to the
+02:00notation. Flip it with a minus when you format. - It depends on the date, not only the place. Daylight saving time makes the offset differ between January and July, so ask the specific
Dateyou care about, notnew Date(). - It describes the device's zone only. JavaScript has no built-in method for the offset of an arbitrary zone, but
Intl.DateTimeFormatwith atimeZoneandtimeZoneNamecan print it. - Find the zone name with
Intl.DateTimeFormat().resolvedOptions().timeZone, which gives an IANA name such as"Europe/Paris". - Don't use it for date arithmetic. Subtracting the offset by hand is error-prone near daylight saving changes. Use the UTC getters and setters or Temporal instead.
- Precision and privacy. The offset reveals roughly where a user is. Some browsers can hide it ("resist fingerprinting" modes report UTC).
- Testing. The result changes with the machine running the test, so avoid asserting exact values unless you set the zone for the whole test run.
Browser support
getTimezoneOffset() works in every browser and runtime.