Get the timezone string
Read the runtime’s IANA time zone, such as America/Sao_Paulo.
function getTimezone() { return Intl.DateTimeFormat().resolvedOptions().timeZone; }
Usage
getTimezone(); // e.g. 'America/Sao_Paulo'
const at = new Date('2026-10-28T12:00:00Z');
at.toLocaleTimeString('en-GB', { timeZone: 'America/Sao_Paulo', hour: '2-digit', minute: '2-digit' }); // → '09:00'
at.toLocaleTimeString('en-GB', { timeZone: getTimezone(), hour: '2-digit', minute: '2-digit' }); // e.g. '09:00'
Know the limits
- Returns the zone of the runtime: the visitor’s in a browser, the server’s (often UTC) in Node.js. Store instants in UTC and convert for display.
- A zone is not an offset: America/Sao_Paulo has had no daylight saving time since 2019, while other zones still shift twice a year.
The function above is the code the usage lines run. It does not validate its arguments; add checks where it receives untrusted input.
Source & maintenance
Based on Get the timezone string from the original 1loc collection by Nguyen Huu Phuoc. Copyright (c) 2020 phuoc-ng. MIT licensed.
Documented as a reference with executed usage lines. Original MDX retained as inert source evidence.
Maintained by Oveyon. Source commit: 14b481cf60df. Read the license.
Keep exploring
- Compare two dates — Compare validated ISO calendar dates in UTC and return -1, 0 or 1.
- Add AM PM suffix to an hour — Turn an hour from 0 to 23 into a 12-hour label with am or pm.
- Calculate the number of days between two dates — Count whole calendar days between two YYYY-MM-DD dates.