Date.prototype.getTimezoneOffset()

Returns the difference in minutes between UTC and local time for the instant the date represents.

Signature
getTimezoneOffset()
  • Added in JavaScript ES1

Return value

numberA number representing the difference, in minutes, between the date evaluated in UTC and the same date evaluated in the local time zone. Returns NaN if the date is invalid.

Changelog

  • PHP Modern enginesOffsets are resolved through the IANA time zone database, so historical dates report the offset that was in force at the time, not today's offset.

getTimezoneOffset() reports how far local time sits from UTC, in minutes, for the instant this particular date represents. It is not a constant property of the machine — call it on a summer date and a winter date in a DST region and you will get two different numbers.

The sign is backwards from what you expect

The value is UTC minus local, so zones ahead of UTC return negative numbers. UTC+2 returns -120; UTC-5 returns 300. Every ISO-style offset string you build from it needs the sign flipped.

When to reach for it

  • Rendering an offset label such as UTC+05:30 next to a time.
  • Detecting whether a given date falls inside daylight saving time, by comparing its offset against January's and July's.
  • Sending the viewer's offset to a server that formats timestamps.

What trips people up

Offsets are not always whole hours — India is -330, Nepal -345 — so always divide by 60 and take the remainder rather than assuming offset / 60 is an integer. And because the result depends entirely on the environment's configured zone, code that branches on a hard-coded offset breaks the moment it runs on a server set to UTC. For real zone work, prefer Intl.DateTimeFormat with an explicit timeZone.

Example

Try it yourself
Loading editor…
Press Run to execute the code.

When to use it

  • Display the viewer's UTC offset beside a rendered timestamp
  • Check whether a specific date falls inside daylight saving time
  • Send the client's offset to an API that renders times server-side
  • Explain a one-hour discrepancy in a date-diff bug report

Frequently asked questions

Why is getTimezoneOffset() negative for my timezone?

Because the value is UTC minus local time, so any zone ahead of UTC comes out negative — Berlin in winter returns -60, not 60. Flip the sign when you build a display string like UTC+01:00.

How do I get the user's timezone name instead of an offset?

Use Intl.DateTimeFormat().resolvedOptions().timeZone, which returns an IANA identifier such as "America/New_York". getTimezoneOffset() only gives you a number of minutes, and many zones share the same offset at different times of year.

Does getTimezoneOffset() change with daylight saving time?

Yes — it reflects the offset in force on the date you call it on, not on today. Calling it on a July date and a January date in a DST region gives values 60 minutes apart, which is the standard way to detect DST.

More examples

Detect daylight saving time

The two logged offsets are equal on a machine with no DST (a server set to UTC prints 0 twice and false), and differ by 60 in a DST region. That difference is exactly what the check keys on — it never hard-codes a zone.

Example · javascript
function isDST(date) {
  const jan = new Date(date.getFullYear(), 0, 1).getTimezoneOffset();
  const jul = new Date(date.getFullYear(), 6, 1).getTimezoneOffset();
  // The standard-time offset is the larger (less negative) of the two
  return date.getTimezoneOffset() < Math.max(jan, jul);
}

console.log("Jan offset:", new Date(2024, 0, 15).getTimezoneOffset());
console.log("Jul offset:", new Date(2024, 6, 15).getTimezoneOffset());
console.log("Jul in DST?", isDST(new Date(2024, 6, 15)));

Half-hour and quarter-hour zones

Shows why offset / 60 is not safe to treat as an integer: India and Nepal are 30 and 45 minutes past the hour. It also makes the sign inversion concrete — the negative inputs are the zones ahead of UTC.

Example · javascript
function label(minutes) {
  const sign = minutes <= 0 ? "+" : "-";
  const abs = Math.abs(minutes);
  return `UTC${sign}${Math.floor(abs / 60)}:${String(abs % 60).padStart(2, "0")}`;
}

console.log(label(-330)); // India
console.log(label(-345)); // Nepal
console.log(label(480));  // US Pacific standard time
console.log(label(0));    // UTC

Discussion

  • Be the first to comment on this lesson.