Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

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+3

Notes

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

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.

Thanks for reading!

Donate to the site — we work hard for you.