The getTimezoneOffset()
method in JavaScript is a part of the Date
object and is used to get the time zone offset, in minutes, for a given date object. The time zone offset is the difference, in minutes, between the date object’s time zone and UTC (Coordinated Universal Time).
Here’s an example of how to use getTimezoneOffset()
to get the time zone offset for the current date and time:
let date = new Date();
let offset = date.getTimezoneOffset();
console.log(offset); // Outputs the time zone offset for the current date and time
You can also pass a date object as an argument to getTimezoneOffset()
to get the time zone offset for a specific date:
let date = new Date(2022, 0, 1, 11, 30, 0); // January 1, 2022 at 11:30:00
let offset = date.getTimezoneOffset();
console.log(offset); // Outputs the time zone offset for January 1, 2022 at 11:30:00
Note that the getTimezoneOffset()
method returns the time zone offset in minutes. If you want to convert the time zone offset to milliseconds, you can multiply it by 60000 (the number of milliseconds in a minute).
Here’s an example of how to use getTimezoneOffset()
to get the time zone offset in milliseconds:
let date = new Date();
let offset = date.getTimezoneOffset() * 60000; // Convert the time zone offset to milliseconds
console.
Leave a Reply