To convert GMT to Chatham Time in JavaScript, you need to create a Date
object with the GMT time and then use the toLocaleString
method to convert it to the Chatham Time. The Chatham Time has an offset of GMT+12.75.
index.tsx295 chars9 lines
In the code above, we created a Date
object with GMT time for January 1st, 2022 at midnight. We then used the toLocaleString
method to convert the GMT time to the Chatham Time with the timeZone
option set to 'Pacific/Chatham'. This option tells JavaScript which time zone to use for the conversion. The output of the console.log
statement is the Chatham Time in the format of MM/DD/YYYY, HH:MM:SS AM/PM
.
gistlibby LogSnag