convert gmt to australian central time in javascript

To convert GMT time to Australian Central Standard Time (ACST) in JavaScript, you can use the Moment.js library. Here's an example code snippet:

index.tsx
// Set the GMT date/time string to be converted
var gmtDateTime = "2021-07-01 10:30:00";

// Parse and format the date/time string with Moment.js
var momentDateTime = moment.utc(gmtDateTime).format();

// Set the timezone to Australian Central Standard Time (ACST)
moment.tz.setDefault("Australia/Adelaide");

// Convert the date/time to ACST
var acstDateTime = moment(momentDateTime).format();

// Output the converted date/time string
console.log(acstDateTime);
464 chars
15 lines

In this example, we first set the GMT date/time string to be converted. We then use Moment.js to parse and format the date/time string. The moment.utc() function is used to parse the date/time string as UTC time, and the .format() function is used to format it as a Moment.js object.

We then set the default timezone to Australian Central Standard Time using the moment.tz.setDefault() function. Finally, we convert the date/time object to ACST using the moment() function and output the converted date/time string using the .format() function.

Note that you'll need to include the Moment.js library in your project for this code to work.

gistlibby LogSnag