Date.prototype.getTimezoneOffset
Returns the difference, in minutes, between UTC and the local time zone
Syntax
date.getTimezoneOffset()Return Value
The time zone offset in minutes (positive for behind UTC, negative for ahead)
Examples
const date = new Date();
console.log(date.getTimezoneOffset());
// -60 for UTC+1, 300 for UTC-5function getUTCOffset(date: Date) {
const offset = -date.getTimezoneOffset();
const hours = Math.floor(Math.abs(offset) / 60);
const mins = Math.abs(offset) % 60;
const sign = offset >= 0 ? '+' : '-';
return `UTC${sign}${hours}:${String(mins).padStart(2, '0')}`;
}const date = new Date();
const utcDate = new Date(date.getTime() + date.getTimezoneOffset() * 60000);
console.log(utcDate);Understanding Date.prototype.getTimezoneOffset
The Date.prototype.getTimezoneOffset method in JavaScript returns the difference, in minutes, between UTC and the local time zone. It belongs to the Date object and is one of the most widely used methods for working with date values in modern JavaScript and TypeScript applications.
The method signature is date.getTimezoneOffset(). When called, it returns the time zone offset in minutes (positive for behind utc, negative for ahead). Understanding when and how to use getTimezoneOffset() helps you write more expressive, readable code.
Common use cases for Date.prototype.getTimezoneOffset include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like date-toisostring, date-tolocalestring, date-now, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Date.prototype.getTimezoneOffset is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Date.prototype.toISOStringReturns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long
Date.prototype.toLocaleStringReturns a string with a language-sensitive representation of this date, including both date and time
Date.nowReturns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC
More Date Methods
Other methods in the Date object
Related Tools
More Date Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.