How to convert timezones in code (DST-correct)

Convert a timestamp between any two IANA zones at the right offset for the date. Examples in curl, JavaScript, and Python.

curl

curl "https://tz.wrapper-agency.com/api/v1/tz?from=America/New_York&to=Asia/Tokyo&time=2008-11-04T09:00"

JavaScript (fetch)

const res = await fetch(
  "https://tz.wrapper-agency.com/api/v1/tz?from=America/New_York&to=Asia/Tokyo&time=2008-11-04T09:00"
);
const { converted, toOffset } = await res.json();
console.log(converted, toOffset); // 2008-11-04T23:00:00 UTC+09:00

JavaScript (no API — pure Intl)

// The same engine this site uses, built in to the runtime:
new Date("2008-11-04T14:00:00Z").toLocaleString("en-US", {
  timeZone: "Asia/Tokyo",
}); // 11/4/2008, 11:00:00 PM

Python (requests)

import requests
r = requests.get(
    "https://tz.wrapper-agency.com/api/v1/tz",
    params={
        "from": "America/New_York",
        "to": "Asia/Tokyo",
        "time": "2008-11-04T09:00",
    },
)
print(r.json()["converted"])  # 2008-11-04T23:00:00

Why naive offsets break

A fixed offset ("New York is UTC−5") is wrong for half the year: during daylight saving it's UTC−4. The correct approach resolves the offset for the specific date of the timestamp — which is what the /api/v1/tz endpoint does, and what makes conversions around clock-change dates accurate.

Epoch (Unix time)

Epoch is timezone-agnostic — it's seconds since 1970 UTC. To display it locally, pass epoch= with a to= zone.

See the full API reference. Data: IANA time zone database via the Intl API.