convert australian eastern daylight time to gmt in typescript

To convert Australian Eastern Daylight Time (AEDT) to GMT, one approach is to use Moment.js, a popular JavaScript date and time library. Here's how to do it in TypeScript:

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

// Set the input timezone to AEDT
const inputTimezone = 'Australia/Sydney';

// Create a Moment object with the input datetime in AEDT
const inputDatetime = moment.tz('2022-05-20 15:30:00', inputTimezone);

// Convert the input datetime to GMT
const outputDatetime = inputDatetime.tz('GMT');

// Format the output datetime as a string
const outputString = outputDatetime.format('YYYY-MM-DD HH:mm:ss');

console.log(outputString); // Output: 2022-05-20 05:30:00
500 chars
16 lines

In this example, we first import the moment-timezone library. We then set the input timezone to Australia/Sydney, which is the timezone for AEDT. We create a moment object with the input datetime in AEDT, and then use the tz method to convert it to GMT. Finally, we format the output datetime as a string and print it to the console.

Note that Moment.js uses the IANA Time Zone database, which contains a comprehensive list of time zones and their corresponding offsets from UTC/GMT.

gistlibby LogSnag