To convert from GMT to New Zealand time in TypeScript, you can use the toLocaleString()
method of the Date
object along with the timeZone
option. Here's an example:
index.ts193 chars4 lines
In this example, we first create a Date
object representing the GMT time using the Date()
constructor and passing in the ISO string for the date and time. The Z
at the end of the string indicates that the time is in GMT.
We then call the toLocaleString()
method on the gmtDate
object, passing in the 'en-NZ'
locale and the timeZone
option with the value 'Pacific/Auckland'
. This will format the date and time in the New Zealand time zone and return a string with the appropriate format.
Finally, we log the formatted date and time to the console.
gistlibby LogSnag