Timezone Conversion in JavaScript: Why getTimezoneOffset() Will Betray You

javascript dev.to

Ask any JavaScript developer how to convert between timezones and someone will say: "use getTimezoneOffset()." Don't. Here's why, and what to use instead. What getTimezoneOffset() Actually Returns const d = new Date(); console.log(d.getTimezoneOffset()); // e.g., -330 for IST, 300 for US/Eastern Two problems with this: 1. It returns the local timezone offset, not an arbitrary one. getTimezoneOffset() tells you the offset of the machine running the code. You cannot use it

Read Full Tutorial open_in_new
arrow_back Back to Tutorials