To convert Australian Western Daylight Time to GMT in JavaScript, you can use the built-in toLocaleString()
method with the timeZone
option to set the time zone of the initial date to AWDT, then convert it to the desired output format with the toLocaleString()
method again using the timeZone
option set to GMT. Here's an example code snippet:
index.tsx316 chars8 lines
In this example, we first create a new date object representing the date and time in AWDT. We then use the toLocaleString()
method with the timeZone
option set to 'Australia/Perth'
to format the date and time string in the AWDT time zone. We then pass this formatted date string to a new Date
object constructor to create a new date object representing the same date and time in the GMT time zone. Finally, we use the toLocaleString()
method again to format the date and time string in the GMT time zone, and log it to the console.
gistlibby LogSnag