Skip to content

Get the timezone from an IP address (and detect a user's time zone)

Detect a user's time zone from their IP address with one API call, or in the browser with Intl. JavaScript, Python and curl examples, plus accuracy notes.

Updated

Short answer: send the IP address to a time zone API: GET /v1/timezone?ip=8.8.8.8 returns America/Chicago, the current offset and the DST flag. In a browser, Intl.DateTimeFormat().resolvedOptions().timeZone is quicker and needs no network call; IP lookup is for servers, emails and first visits.

curl "https://api.timelogicapi.com/v1/timezone?ip=8.8.8.8&api_key=$TIMELOGIC_API_KEY"
{
  "unix": 1793377374,
  "unix_ms": 1793377374309,
  "utc": "2026-10-30T16:22:54Z",
  "iso_local": "2026-10-30T11:22:54-05:00",
  "rfc2822": "Fri, 30 Oct 2026 11:22:54 -0500",
  "human": "October 30, 2026, 11:22 AM America/Chicago",
  "day_number": 6,
  "day_short": "Fri",
  "day_full": "Friday",
  "timezone": "America/Chicago",
  "offset": -300,
  "dst": true
}

That response is real (October 30, 2026). offset is in minutes; timezone is the canonical IANA name you should store.

Which method should I use to detect a user's time zone?

SituationBest method
JavaScript running in the user's browserIntl.DateTimeFormat().resolvedOptions().timeZone
Server handling a user's requestPass their public IP: /v1/timezone?ip=…
A device or script asking about itself/v1/time/current?auto_tz=true or /api/ip
User picked a place on a mapCoordinates: timezone from latitude and longitude
Accuracy really matters (billing, legal deadlines)Ask the user, then store the IANA name

Node.js: time zone of the visitor's IP

// Express example. Behind a proxy, enable "trust proxy" so req.ip is the client's address.
app.get("/welcome", async (req, res) => {
  const url = `https://api.timelogicapi.com/v1/timezone?ip=${encodeURIComponent(req.ip)}`;
  const tz = await fetch(url, { headers: { "X-API-Key": process.env.TIMELOGIC_API_KEY } })
    .then((r) => (r.ok ? r.json() : null));
  res.json({ timezone: tz?.timezone ?? "UTC", localTime: tz?.iso_local });
});

Python: time zone from an IP address

import os, requests

def timezone_for_ip(ip: str) -> str | None:
    r = requests.get(
        "https://api.timelogicapi.com/v1/timezone",
        params={"ip": ip},
        headers={"X-API-Key": os.environ["TIMELOGIC_API_KEY"]},
        timeout=5,
    )
    return r.json()["timezone"] if r.ok else None

print(timezone_for_ip("2001:4860:4860::8888"))

Browser: no API call needed

const zone = Intl.DateTimeFormat().resolvedOptions().timeZone; // e.g. "Europe/Berlin"

That is the device setting. Combine both: use the browser value when you have it, and the IP lookup for API clients, emails and server-side defaults.

Several IPs at once

Comma-separate up to 10 addresses: GET /v1/time/current?ip=8.8.8.8,1.1.1.1 returns an array in input order, each with its own zone and local time. See bulk requests.

Coming from worldtimeapi.org/api/ip?

/api/ip and /api/ip/{ip} work unchanged on api.timelogicapi.com (with a key) and return the same 15 fields; see the migration guide.

Related guides

Frequently asked questions

How do I get the time zone from an IP address?

Call GET https://api.timelogicapi.com/v1/timezone?ip=8.8.8.8 with your API key. The response names the IANA zone (America/Chicago for 8.8.8.8 on October 30, 2026), the current offset in minutes and whether DST is in effect. IPv4 and IPv6 both work.

How do I detect the time zone of the person calling my API?

Use the caller's IP. On the /v1 API, GET /v1/time/current?auto_tz=true uses the request IP's time zone; on the WorldTimeAPI-compatible routes, GET /api/ip does the same. If your server makes the call on behalf of a user, pass the user's IP with ip= instead, because otherwise the zone is your server's.

What is the best way to get a user's time zone in the browser?

Intl.DateTimeFormat().resolvedOptions().timeZone returns the IANA zone the device is set to, with no network call. Use the IP lookup on the server, for emails, first visits and API clients that have no browser.

How accurate is IP-based time zone detection?

Good for a default, not for a guarantee. IP data maps addresses to locations, and VPNs, proxies, mobile carriers and corporate networks can put a user in another region. Let users change the detected zone, and store their choice.

What happens with a private IP address?

Private, reserved and loopback addresses such as 10.0.0.1 or ::1 have no location, so /v1/timezone returns 404 NOT_FOUND. Pass the client's public IP, which you may need to read from a proxy header such as X-Forwarded-For.