To convert a GMT datetime to Hawaii time in Typescript, we can use the Moment.js library along with the Moment Timezone plugin.
First, install the necessary dependencies:
35 chars2 lines
Then, we can use the moment
function to create a new Moment object with the GMT datetime, and use the tz
method to convert to Hawaii time:
index.ts266 chars7 lines
In the code above, we create a Moment object from the GMT datetime using the moment
function. Then, we use the tz
method to convert to Hawaii time, specifying the 'Pacific/Honolulu'
timezone. Finally, we format the resulting datetime string using the format
method, with the 'YYYY-MM-DD HH:mm:ss z'
format string.
The resulting hawaiiDatetime
variable will contain the Hawaii datetime converted from the original GMT datetime.
gistlibby LogSnag