convert gmt to australian western daylight time in javascript

To convert GMT to Australian Western Daylight Time in JavaScript, you can use the built-in Date object and its methods.

Here is an example code snippet that demonstrates how to do this:

index.tsx
// Create a new Date object based on the GMT time
let gmtDate = new Date('2021-10-31T02:30:00Z');

// Get the UTC offset in minutes for Australian Western Daylight Time
let awdtOffset = 540;

// Add the offset to the GMT time in minutes
let awdtTime = gmtDate.getTime() + (awdtOffset * 60 * 1000);

// Create a new Date object based on the Australian Western Daylight Time
let awdtDate = new Date(awdtTime);

// Log the result to the console
console.log(awdtDate);
465 chars
15 lines

In this code snippet, we first create a new Date object based on the GMT time. We then get the UTC offset in minutes for Australian Western Daylight Time, which is 540 minutes ahead of GMT. We add this offset to the GMT time in minutes, and create a new Date object based on the result.

Note that this code assumes that the input date is in ISO format with a 'Z' at the end indicating GMT. If your input date is in a different format, you may need to modify the code accordingly.

gistlibby LogSnag