How to set timezone offset using JavaScript ? Last Updated : 06 Dec, 2024 Comments Improve Suggest changes Like Article Like Report The timezone offset represents the difference in minutes between local time and Coordinated Universal Time (UTC). Here are two different ways to set the timezone offset in JavaScript.1. Using getTimezoneOffset() MethodThe getTimezoneOffset() method is used to find the timezone offset. It returns the timezone difference in minutes, between the UTC and the current local time. If the returned value is positive, the local timezone is behind the UTC and if it is negative, the local timezone is ahead of UTC. The returned value is not constant if the host system is configured for daylight saving. JavaScript // Date object let date = new Date(); // Offset variable will store // timezone offset between // UTC and your local time let offset = date.getTimezoneOffset(); console.log("Timezone offset: ", offset, " minutes"); OutputTimezone offset: 0 minutes Note: The method returns your local timezone offset in minutes and not the timezone offset of the "date" object.2. Using Intl.DateTimeFormat() with TimezoneThe Intl.DateTimeFormat with the timeZone option allows formatting dates according to a specific timezone for display purposes. This method doesn’t alter the underlying date object but formats the date string to reflect the specified timezone, providing a locale-sensitive way to present time. JavaScript // Create Date object for current date/time let date = new Date(); // Format date for 'America/New_York' timezone let formattedDate = new Intl.DateTimeFormat('en-US', { timeZone: 'America/New_York', // Set timezone year: 'numeric', // Show year month: '2-digit', // Show month day: '2-digit', // Show day hour: '2-digit', // Show hour minute: '2-digit', // Show minute second: '2-digit', // Show second hour12: true // Use 12-hour format }).format(date); // Log formatted date console.log(`Formatted Date (New York Time): ${formattedDate}`); OutputFormatted Date (New York Time): 12/05/2024, 09:11:42 PM Comment More infoAdvertise with us Next Article How to set timezone offset using JavaScript ? R riyakalra59 Follow Improve Article Tags : JavaScript Web Technologies javascript-date JavaScript-Questions Similar Reads How to get the client timezone offset in JavaScript? The client's timezone offset could be detected by using the Date object's getTimezoneOffset() method. The getTimezoneOffset() method returns the time difference between UTC time and local time, that is the time offset, in minutes. This offset is changed by dividing by 60 and negating the result. Not 1 min read How to get JavaScript Date in UTC using MomentJS? When working with dates and times in JavaScript, especially in applications that deal with users across different time zones, it is often necessary to work with dates in UTC (Coordinated Universal Time). Below are the approaches to get a date in UTC using Moment.js:Table of ContentUsing moment().utc 2 min read How to convert UTC date time into local date time using JavaScript ? Given an UTC date and the task is to convert UTC date time into local date-time using JavaScript toLocaleString() function. Syntax: var theDate = new Date(Date.parse('DATE_IN_UTC')) theDate.toLocaleString() Example 1: This example converts UTC date time into local date time using JavaScript. html 1 min read JavaScript Date toGMTString() Method The date.toGMTString() method is used to convert the given date objectâs contents into a string according to the Greenwich Mean Time GMT. The date object is created using the date() constructor. Note: This method has been deprecated and has been replaced by the toUTCString() method. Syntax: dateObj. 2 min read How to get seconds since epoch in JavaScript? Given a date, we have to find the number of seconds since the epoch (i.e. 1 January 1970, 00:00:00 UTC ). The getTime() method in the JavaScript returns the number of milliseconds since January 1, 1970, or epoch. If we divide these milliseconds by 1000 and then integer part will give us the number o 1 min read Like