convert gmt to australian central standard time in javascript

Here is an example of how to convert GMT to Australian Central Standard Time using the Moment.js library in JavaScript:

index.tsx
// Define the GMT date and time
var gmtDate = '2021-07-30T18:00:00.000Z';

// Use Moment.js to convert to ACDT (Australian Central Daylight Time)
var acdtDate = moment.utc(gmtDate).tz('Australia/Adelaide').format();

console.log(acdtDate); // Outputs "2021-07-31T04:30:00+09:30"
279 chars
8 lines

In this example, we first define a date and time in GMT format ('2021-07-30T18:00:00.000Z'). We pass this string to Moment.js to create a new Moment object in UTC time. We then call the tz() method to convert the Moment object to the desired timezone (in this case, 'Australia/Adelaide' for the Australian Central Daylight Time zone). Finally, we call the format() method to output the date and time in a readable format. The resulting output in this example would be '2021-07-31T04:30:00+09:30'.

gistlibby LogSnag