To convert a GMT date to Samoa Time in Typescript, we can use the date-fns
library which provides a simple and easy-to-use API for manipulating dates and times.
First, we need to install date-fns
using npm:
index.ts21 chars2 lines
Then, we can create a new Date
object with our GMT time and use the add
function to add the Samoa Time offset:
index.ts269 chars10 lines
In this example, we use the add
function to add 13 hours to the GMT date which corresponds to the Samoa Time offset.
Note that we use the toISOString
function to convert the Samoa Time date to a string representation in ISO 8601 format.
gistlibby LogSnag