To convert Samoa time to GMT in TypeScript, we can use the Moment.js library which provides functionality to work with dates and timezones.
First, we need to install Moment.js library in our project using package manager like npm or yarn.
index.ts36 chars2 lines
Then we can use the moment()
function to create a moment object representing Samoa time, specifying the Pacific/Samoa
timezone:
index.ts110 chars4 lines
Next, we can use the utc()
method with no arguments to convert the moment object from Samoa time to UTC/GMT:
index.ts33 chars2 lines
Finally, we can format the moment object as a string in the desired format using the format()
method:
index.ts61 chars2 lines
Putting it all together, here's the TypeScript code to convert Samoa time to GMT:
index.ts264 chars8 lines
gistlibby LogSnag