To convert New Zealand Time (NZT) to Greenwich Mean Time (GMT) in TypeScript, you can use the following function:
index.ts259 chars8 lines
The function takes a Date
object representing a time in NZT and returns a new Date
object representing the equivalent time in GMT.
The function works by calculating the difference between the NZT offset from UTC (which is +12 hours) and the GMT offset from UTC (which is 0 hours). It then subtracts this difference from the input Date
object's time in milliseconds and creates a new Date
object representing the new time in GMT.
Example usage:
index.ts169 chars4 lines
In this example, the input Date
object represents a time of 12:34:56 PM on June 30, 2021 in NZT. The output Date
object represents the equivalent time in GMT, which is 12:34:56 AM on the same day. The output is in ISO 8601 format.
gistlibby LogSnag