convert gmt to australian central standard time in typescript

To convert GMT to Australian Central Standard Time, we can use the moment-timezone library in TypeScript. Here's an example code:

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

const gmtDate = "2021-10-20 10:00:00 GMT";
const acstDate = moment.tz(gmtDate, "GMT").tz("Australia/Adelaide");

console.log(acstDate.format()); // 2021-10-20T20:30:00+10:30
218 chars
7 lines

In this code, we first import the moment-timezone library. We then define a variable gmtDate which is the date in GMT. We pass this date and the GMT timezone to the moment.tz() method to create a moment object with the GMT timezone.

We then use the tz() method again to convert this moment object to the Australian Central Standard Timezone. In this case, we're converting to the Adelaide timezone.

Finally, we print the formatted date in the console using the format() method.

Note that we need to specify the Australia/Adelaide timezone for Australian Central Standard Time. You can replace this value with any other Australian timezone that you want to convert to.

gistlibby LogSnag