nicetool.dev logo
#datetime#backend#timezones

Time Zones, UTC and DST: The Rules Every Developer Gets Wrong Once

Why you should store time in UTC, the difference between an offset and a time zone, how daylight saving creates missing and doubled hours, and the IANA database that keeps it all straight.

5 min read

Almost every developer ships a time zone bug at least once: a meeting that shows up an hour off, a report that double-counts a day, a cron job that fires twice one morning in March. Dates and times feel simple until two places, or two times of year, disagree about what "now" means. This article lays out the small set of rules that prevent most of those bugs.

Store time in UTC. Always.

UTC (Coordinated Universal Time) is the global reference clock. It does not observe daylight saving and never shifts. The single most important rule in all date handling is: store and compute in UTC, convert to local time only when you show it to a person.

A Unix timestamp (the number of seconds since 1970-01-01 UTC) is already UTC by definition, which is why it is such a reliable way to store an instant. If you store 1764763200, everyone agrees on the exact moment it refers to, no matter where their server is.

What goes wrong when you don't:

  • You store 2026-12-03 09:00 with no zone. Is that Hanoi time? London time? The server's local time? Nobody knows, and the answer changes when you move the server to a different region.
  • You do date math across a daylight-saving change and get an answer that is off by an hour.
  • Two users in different countries see the same event at different wall-clock times, which is correct, but your database row can only be right if it stored one unambiguous instant.

Store the instant (UTC or a Unix timestamp). Store the user's zone separately if you need to show or reason about their local time.

An offset is not a time zone

This is the distinction that trips people up most.

  • An offset is a fixed difference from UTC at one moment, like +07:00 or -05:00.
  • A time zone is a place with a set of rules about which offset applies at which time of year, like Asia/Ho_Chi_Minh or America/New_York.

America/New_York is -05:00 in winter and -04:00 in summer. If you only store -05:00, you have thrown away the information needed to know what the offset will be next July. A place is not the same as its current offset. This is why +07:00 is not a substitute for Asia/Ho_Chi_Minh, even though Vietnam happens to stay on +07:00 all year: the offset cannot tell you the rules, only the zone can.

So: to represent a future local time ("9am on the first Monday of every month in New York"), store the zone name, not an offset. To represent a past instant, UTC or a Unix timestamp is enough.

Daylight saving time breaks two assumptions

Daylight Saving Time (DST) shifts the clock forward in spring and back in autumn in many countries. It quietly breaks two things programmers assume are always true.

1. Not every day has 24 hours. On the spring-forward day the clock jumps from 01:59 to 03:00, so that day has 23 hours and the time 02:30 does not exist. On the autumn day the clock falls from 02:59 back to 02:00, so that day has 25 hours and 02:30 happens twice. Code that adds "24 hours" to get "tomorrow at the same time" will be an hour off on these two days. Add "1 day" using a calendar-aware library instead, which lands on the same wall-clock time.

2. A local time can be missing or ambiguous. If a user enters 02:30 on the spring-forward day, that time never happened. If they enter 02:30 on the autumn day, you cannot tell which of the two you mean without more information. Good date libraries let you choose how to resolve these (for example, roll forward, or pick the earlier instant); naive code silently guesses.

This is also why cron can misfire: a job scheduled for 02:30 local time is skipped on the spring day and runs twice on the autumn day. Scheduling in UTC avoids it entirely.

Not every country uses DST. Vietnam, most of Asia and all of China (one zone for the whole country) do not, which is one reason bugs from DST often appear only when a product expands to Europe or North America.

The IANA time zone database

How does a computer know that New York springs forward on the second Sunday of March? From the IANA time zone database (also called tz or zoneinfo), a public dataset that records every zone's rules and all of their historical changes. It ships with operating systems, browsers and language runtimes, and is updated several times a year as governments change their rules, sometimes with only weeks of notice.

Two practical consequences:

  • Use canonical zone names like Asia/Ho_Chi_Minh or Europe/London, in the Region/City form. Avoid the old three-letter abbreviations like EST or ICT: they are ambiguous (IST is used for India, Ireland and Israel) and do not capture DST rules.
  • Keep the database current. If your server's tz data is stale, a government's recent change (say, a country abolishing DST) will be computed wrong. This usually means keeping the OS and your language runtime updated.

Use the platform, don't hand-roll

Modern JavaScript can do correct zone conversions with the built-in Intl API and no library:

new Intl.DateTimeFormat('en-GB', {
  timeZone: 'Asia/Ho_Chi_Minh',
  dateStyle: 'medium',
  timeStyle: 'short',
}).format(new Date());        // "3 Dec 2026, 16:00"

For arithmetic (add a day, find the offset, compare zones), use a library that understands the tz database: dayjs with its UTC and timezone plugins, date-fns-tz, or the newer built-in Temporal API. Never compute offsets by adding hours yourself: you will get DST wrong. On the backend, store TIMESTAMP WITH TIME ZONE (or a Unix timestamp) rather than a naive local timestamp.

A checklist

  • Store instants in UTC (or as a Unix timestamp); convert to local only for display.
  • Store a zone name (Asia/Ho_Chi_Minh), not an offset (+07:00), when you need future local times.
  • Never assume a day is 24 hours or that every local time exists exactly once.
  • Schedule recurring jobs in UTC to avoid the DST double/skip.
  • Use Intl or a tz-aware library; keep the OS tz database updated.
  • Use canonical Region/City zone names, not three-letter abbreviations.

When you need to see what a given instant looks like across several cities at once, or check what the offset will be on a future date, paste it into the Time Zone Converter. It uses the IANA database through your browser, so the DST rules are always the ones your system knows. To convert a stored Unix timestamp to a readable date first, the Unix Time Converter does that in one step.

Written by

Nguyễn Thành Nam

Full-Stack Engineer · Backend & Platform

Full-stack engineer with 9+ years of experience building high-traffic APIs and platforms with Go, NestJS, PHP (Laravel, Phalcon) and Node.js. Specializes in GraphQL API design, real-time systems and performance optimization, and builds NICETOOL.dev for the developer community.

Try it yourself

Related articles