To convert a GMT timestamp to Mountain Time in TypeScript, we can use the moment-timezone library.
First, we need to install the moment-timezone library using NPM:
28 chars2 lines
Then, we can use the following code snippet to convert the GMT timestamp to Mountain Time:
index.ts234 chars6 lines
In the code above, we first create a moment object using the moment.utc() method and pass the GMT timestamp as a parameter. This creates a moment object with the UTC time zone.
We then use the tz() method to convert the UTC time zone to the Mountain Time zone. We pass the America/Denver time zone identifier as a parameter to the tz() method.
Finally, we use the format() method to format the output in the desired format ('YYYY-MM-DD HH:mm:ss') and log it to the console.
The output will be in the Mountain Time zone, which is 6 hours behind the GMT time zone.
gistlibby LogSnag