One way to convert Australian Eastern Time (AET) to Greenwich Mean Time (GMT) in JavaScript is to use the Moment.js library. Here's an example code snippet:
index.tsx441 chars14 lines
In this example, we first define a date and time string in AET ('2021-08-31T14:30:00+10:00'). We then create a Moment.js object and parse this string using the moment
function.
Next, we use the clone
method to create a new Moment object that is a clone of our AET object. We then call the utc
method to convert this clone to GMT.
Finally, we use the format
method to format the GMT date and time string in a specific format ('YYYY-MM-DD HH:mm:ss [GMT]'). We then output this string to the console.
Note that Moment.js uses the IANA time zone database to handle time zones correctly. This means that you may need to adjust your AET date and time string to include the correct time zone offset (in this example, we included the +10:00 offset to indicate AET).
gistlibby LogSnag