get user timezone

get user timezone

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Determining User Timezone in Web Applications

Determining a web user's timezone is frequently misunderstood as a capability of the browser or the server alone, but it is fundamentally a client-side responsibility. The operating system on the user's device holds the definitive truth about their local time and region settings, not the HTTP request headers sent to your backend. While you can infer location data from IP addresses using third-party geolocation APIs, relying on that method introduces significant inaccuracies because users often travel, use virtual private networks (VPNs), or simply have incorrect ISP routing data. The only reliable way to know a user's timezone is to ask them directly through their device settings.

In the context of modern web development, this means the primary mechanism for capturing timezone preference is the Timezone API available in JavaScript. This interface allows you to query the browser's internal clock and regional settings without requiring any external libraries or server-side logic. When a user loads your page, the browser exposes an object that represents their local time zone offset, such as America/New_York or Europe/London.

You can access this information via the following snippet:

const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
console.log(`User's timezone: ${timezone}`);
// Output might be "America/Chicago" or "Asia/Tokyo"

This code leverages the Intl object, which is part of the standard JavaScript specification. The resolvedOptions() method returns a dictionary of options that were used to create the formatter, including the timezone string in IANA format. This approach works across all modern browsers that support ECMAScript 2019 or later. If you need to support older environments like Internet Explorer, you might encounter compatibility issues, though relying on IE for timezone data is generally inadvisable given its end-of-life status.

Once you have the timezone string from the client, you must transmit it to your server. You can achieve this by including it in the HTTP request headers or embedding it in a hidden form field during submission. A common pattern involves sending it as a custom header:

fetch('/api/save-data', {
  method: 'POST',
  headers: {
    'Timezone': Intl.DateTimeFormat().resolvedOptions().timeZone,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ data: "some user data" })
});

Alternatively, if your application uses a framework like Laravel, you can automatically inject this value into the request. In Laravel, while there isn't a built-in middleware that defaults to request()->header('Timezone') out of the box without configuration, you can create a custom middleware or trait to centralize this logic. This ensures that every controller action has access to the user's timezone preference via $request->header('Timezone').

There are distinct trade-offs to consider when handling timezone data. Storing the offset (e.g., UTC-5) is insufficient because it changes with Daylight Saving Time transitions and does not provide a consistent identifier for the region. Always store the IANA timezone string (like America/Los_Angeles) in your database. This string remains constant regardless of whether the region is currently observing standard or daylight time, allowing your application to dynamically calculate the correct offset based on the current date.

If you are building a Laravel application specifically, leveraging packages like spatie/laravel-activitylog often includes timezone detection logic automatically, but for custom implementations, you must explicitly handle the header injection. Avoid assuming that the server's system timezone matches the user's; always default to UTC for storage and conversion on-the-fly when displaying data. This separation of concerns ensures your application remains robust against users traveling across time zones or changing their location settings while logged in.

For more advanced scenarios involving complex localization requirements, such as formatting dates according to specific regional conventions beyond just the timezone string, you might explore internationalization packages. While the core concept relies on the client providing the data, the architecture of how you store and utilize that data defines the reliability of your application's date handling.

Our network