Programming
We provide developers and engineers the guides and tutorials they...
Search
We provide developers and engineers the guides and tutorials they...
Content is king. It's not just about how you're going to write, b...
Looking for an engaging connection with thousands of other people...
Why time zones are hard for programmers: offsets vs zones, daylight saving gaps and overlaps, changing rules and leap seconds, plus rules for storing time.
Quick answer: Time zones are hard because local time is defined by politics, not physics. Governments choose their offsets from UTC and their daylight saving rules, and they change them, sometimes with only weeks of notice. As a result a local time can not exist (when clocks jump forward), can happen twice (when they fall back), and a day is not always 24 hours long. On top of that, an offset such as +02:00 is not the same thing as a time zone such as Europe/Paris. The working rules: store moments in UTC, convert to local time only for display, keep the named zone for future events, and use a proper date library.
Also Read: Why Do Computers Need Both RAM and Storage? - How To's
"Each country has a fixed offset from Greenwich, and some add an hour in summer."
Almost every part of that is wrong.
India is UTC+5:30. Nepal is UTC+5:45. Parts of Australia use +9:30 and +8:45. The full range runs from UTC-12 to UTC+14, so two places can show the same clock time on different calendar dates.
Governments abolish daylight saving, adopt it, move the dates, or change their base offset. Some changes have been announced days in advance. Samoa moved across the International Date Line at the end of 2011 and skipped 30 December entirely.
On the spring change in a zone that moves from 02:00 to 03:00:
| Wall clock | Exists? |
|---|---|
| 01:59 | Yes |
| 02:30 | No |
| 03:00 | Yes |
On the autumn change, 01:30 happens twice, an hour apart. A timestamp of "01:30" without an offset is ambiguous.
So a day can be 23, 24 or 25 hours long. Code that adds 24 hours to mean "tomorrow" is wrong twice a year.
CST is Central Standard Time, China Standard Time and Cuba Standard Time. IST is India, Ireland and Israel. Never parse or store them.
This is the distinction that matters most.
| Example | What it tells you | |
|---|---|---|
| Offset | +02:00 | The difference from UTC at one moment |
| Time zone | Europe/Paris | A region and its full history of rules, past and future |
Paris is +01:00 in winter and +02:00 in summer. Knowing that a timestamp was +02:00 does not tell you what the offset will be six months later.
The rules live in the tz database, also called the IANA or Olson database. It names zones as Area/Location, such as America/New_York or Asia/Kolkata, and records every known change for each.
It is maintained by volunteers and updated several times a year. Your operating system, language runtime and database each ship a copy. If those copies are out of date, your software computes wrong local times for the affected regions. Keeping them updated is a real maintenance task.
A Unix timestamp counts seconds since 1 January 1970, 00:00 UTC. It identifies a moment unambiguously, with no zone involved. See Unix time.
For text, use the ISO 8601 style defined for internet use in RFC 3339:
2026-10-04T14:30:00Z the Z means UTC
2026-10-04T16:30:00+02:00 the same instant, written with an offset
Avoid 10/04/2026. It is 4 October in the United States and 10 April in much of the rest of the world.
Three kinds of value are easy to confuse:
| Kind | Example | Use |
|---|---|---|
| Instant | 2026-10-04T14:30:00Z | When something happened |
| Local date-time | 2026-10-04 09:00 | A wall-clock reading with no zone |
| Date only | 1990-05-17 | Birthdays, due dates |
Most bugs come from treating one kind as another.
Europe/Berlin next year should stay at 09:00 Berlin time even if Germany changes its rules. If you had converted to UTC in advance, it would silently move.java.time, Python's zoneinfo, JavaScript's Temporal or Intl, Noda Time. Do not do offset arithmetic by hand.created_at_utc, starts_at_local, timezone. See why naming things is so hard.from datetime import datetime
from zoneinfo import ZoneInfo
utc = datetime(2026, 10, 4, 14, 30, tzinfo=ZoneInfo("UTC"))
print(utc.astimezone(ZoneInfo("Asia/Kolkata"))) # 2026-10-04 20:00:00+05:30
A database note: in PostgreSQL, timestamp with time zone does not store a zone. It converts the input to UTC and stores the instant. timestamp without time zone stores the wall-clock digits with no meaning attached. Know which one you are using.
Date, which parses date-only strings as UTC and date-time strings as local, and counts months from zero.Time belongs with Unicode and floating-point numbers on the list of things that seem simple until real data arrives.
For moments that have already happened, yes. For future events tied to a place, store the local time and the named time zone.
UTC is the modern time standard based on atomic clocks. GMT is a time zone that currently has the same clock time. For most software they can be treated as equal, but UTC is the correct term.
An offset is a fixed difference from UTC. A time zone is a set of rules for a region that determines the offset at any given date.
It was probably scheduled in local time during the hour that repeats when clocks go back.
Time zones are difficult because they encode human decisions that are irregular and keep changing. You cannot simplify them away, but you can contain them: keep instants in UTC, keep the named zone when the local time is what matters, convert only at the edges, and let a maintained library and the tz database carry the rules.