To convert from GMT (Greenwich Mean Time) to Australian Western Time, we can use Moment.js and Moment Timezone libraries. Here's an example of how to do it in TypeScript:
index.ts261 chars7 lines
Explanation:
'2022-01-01T12:00:00Z'
(note the Z
at the end which stands for Zulu time, or GMT).moment()
function with the GMT date passed as an argument.tz()
function to convert the moment object to the AWT timezone by passing 'Australia/Perth'
as an argument. Note that the 'Australia/Perth'
timezone identifier is specific to Moment Timezone library and corresponds to Australian Western Standard Time (AWST).toDate()
function to convert the moment object back to a Date object with the AWT time.The resulting AWT date is 2022-01-01T20:00:00.000Z
, which is 8 hours ahead of the GMT date.
gistlibby LogSnag