convert australian central daylight time to gmt in typescript

To convert Australian Central Daylight Time (ACDT) to Greenwich Mean Time (GMT) in TypeScript, you can use the Moment.js library along with the timezone data. Here's an example code snippet:

index.ts
import * as moment from 'moment-timezone';

// set the timezone to ACDT
const inputTime = moment.tz('2021-06-01 12:00:00', 'Australia/Adelaide');

// convert to GMT
const outputTime = inputTime.clone().utc();

// format output time as desired
const formattedTime = outputTime.format('YYYY-MM-DD HH:mm:ss');

console.log(formattedTime); // output: 2021-06-01 02:30:00
367 chars
13 lines

In this example, we first set the input time to a specific date and time in ACDT, using the moment.tz function to set the timezone. We then use the utc method to convert the input time to GMT. Finally, we format the output time using the format method and log it to the console.

Make sure you have installed the moment-timezone package by running npm install moment-timezone in your project terminal.

gistlibby LogSnag