To convert Chatham time to GMT in Javascript, we can use the getTimezoneOffset()
method of the Date
object. Chatham time is in GMT+12:45 time zone, meaning it is 12 hours 45 minutes ahead of GMT. So, to get the corresponding GMT time, we can subtract 12 hours 45 minutes from the Chatham time. Here's an example code snippet:
index.tsx584 chars14 lines
Note that the getTimezoneOffset()
method returns the difference, in minutes, between the local time zone and UTC/GMT. So, we need to multiply it by 60*1000 to convert it to milliseconds. Also, we subtract the timezone offset from the Chatham time so that we can get the correct GMT time. The resulting gmtTime
object represents the corresponding GMT time, which we can format as a string using the toUTCString()
method.
gistlibby LogSnag