To convert Australian Central Time to GMT in TypeScript, you can use the built-in Date
object and its methods. Here is an example code snippet:
index.ts404 chars11 lines
In this example, we set the date and time for Australian Central Time by passing the UTC offset of +9:30 to the Date
constructor. Then, we get the UTC time in milliseconds by subtracting the time zone offset (in minutes) from the date's time value using the getTime()
and getTimezoneOffset()
methods.
Next, we create a new Date
object with the computed UTC time value and format it as a string in GMT using the toUTCString()
method. Finally, we log the output to the console.
Note that this code assumes that the input date string is in ISO 8601 format, which is supported by most modern browsers. However, if you need to support other date formats, you may need to use a third-party library such as Moment.js for parsing and formatting dates. Additionally, keep in mind that this code only converts a single date/time value and does not handle recurring events or daylight saving time changes.
gistlibby LogSnag