To convert GMT to Australian Central Time in TypeScript, you can use the date-fns and timezone libraries.
Here is an example code snippet that demonstrates how to convert a GMT string to Australian Central Time:
index.ts304 chars12 lines
In the code above, we first import the required functions from the date-fns-tz library. We then define the GMT date string and the target time zone which is Australian Central Time in this case.
We then create a Date object from the GMT date string and pass it to the utcToZonedTime
function along with the target time zone. This function returns a Date object adjusted to the target time zone.
Finally, we log the converted date to the console.
Another option to achieve this conversion is using the Moment.js library. Here is an example code snippet that demonstrates how to convert GMT to Australian Central Time using Moment.js:
index.ts240 chars11 lines
In this code, we first import the Moment.js library. We then define the GMT date string and the target time zone which is Australian Central Time in this case.
We create a moment object from the GMT date string and use the tz
function to convert it to the target time zone.
Finally, we log the converted date to the console.
gistlibby LogSnag