You can use the Moment.js library to easily handle and convert timezones in JavaScript. Here's an example of how to convert a GMT date string to Australian Eastern Standard Time (AEST):
index.tsx349 chars14 lines
In the code above, we first load the Moment.js library and then define a GMT date string as gmtDate
. We then use the moment()
function to parse the GMT date and convert it to the desired timezone using the tz()
function, which takes the timezone identifier as a parameter. In this case, we use Australia/Sydney
to convert to AEST.
To output the result, we use the format()
function to return the date in ISO 8601 format with timezone offset.
Note that we need to install the moment-timezone
package via npm, which is a Moment.js plugin that provides zone data for timezones. You can find a list of timezone identifiers to use with the tz()
function on the Moment.js website.
gistlibby LogSnag