convert gmt to australian eastern daylight time in typescript

To convert GMT (Greenwich Mean Time) to Australian Eastern Daylight Time in TypeScript, you can use the Moment.js library. Moment.js provides an easy and intuitive way to manipulate and display dates and times in various time zones.

Here's an example code snippet that demonstrates how to convert a GMT date-time string to Australian Eastern Daylight Time string.

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

const gmtDateTime = '2021-10-18T03:15:00Z'; // GMT date-time string
const ausDateTime = moment(gmtDateTime).tz('Australia/Sydney').format(); // Australian Eastern Daylight Time string

console.log(ausDateTime); // Output: 2021-10-18T14:15:00+11:00
287 chars
7 lines

In the code snippet above, we first import the Moment.js library. We then define a gmtDateTime variable containing a GMT date-time string (in ISO format). Next, we use the Moment.js moment() function to parse the GMT date-time string and create a moment object. We then use the tz() function to convert the moment object from GMT to Australian Eastern Daylight Time by specifying the 'Australia/Sydney' time zone. Finally, we use the format() function to convert the moment object to a string, which is in the ISO format with the local time zone offset (+11:00).

The resulting value of ausDateTime is a string representing the Australian Eastern Daylight Time version of the input date-time in ISO format.

gistlibby LogSnag