Timezone as Zone, string, or offset in minutes
Optionalts: numberOptional timestamp (milliseconds) for IANA zone offset calculation. Defaults to current time if not provided.
Zone offset in "+HH:MM" format, or "" if zone is invalid
// Fixed offsets
zoneToShortOffset("UTC+8") // "+08:00"
zoneToShortOffset(480) // "+08:00"
zoneToShortOffset("UTC-5:30") // "-05:30"
// IANA zones (offset depends on DST)
const winter = new Date("2023-01-15").getTime()
const summer = new Date("2023-07-15").getTime()
zoneToShortOffset("America/Los_Angeles", winter) // "-08:00" (PST)
zoneToShortOffset("America/Los_Angeles", summer) // "-07:00" (PDT)
// Invalid zones return empty string
zoneToShortOffset("invalid") // ""
zoneToShortOffset(null) // ""
Convert a timezone to its short offset format (e.g., "+08:00", "-05:00").
Useful for displaying timezone offsets in a standardized format. For IANA zones with daylight saving time, provide a timestamp to get the correct offset for that moment.