Most time zone bugs come from storing the wrong thing. These rules keep scheduling, billing and logging code correct across daylight saving changes and travel.
1. Store instants in UTC
Save timestamps as UTC (ISO 8601 with Z, a Unix timestamp, or a timestamptz column). Convert to local time only when you display it.
2. Store the IANA zone name, not an offset or abbreviation
America/New_York knows its DST history and future; -05:00 is only correct for part of the year, and abbreviations like CST are ambiguous (US Central, China, Cuba).
3. Future local events need the zone, not just UTC
For a meeting at 9:00 AM London time next July, store the local time plus Europe/London. If you pre-convert to UTC and the government changes DST rules, the meeting will be wrong.
4. Handle gaps and overlaps
When clocks spring forward, local times like 2:30 AM do not exist; when they fall back, 1:30 AM happens twice. Decide explicitly how your code resolves them (for example Python's fold, or Java's ZonedDateTime rules).
5. Never do date maths with fixed 24-hour days
A DST day lasts 23 or 25 hours. Add calendar days in the local zone, not 86,400 seconds.
| Language | Convert a UTC instant to a zone |
|---|---|
| JavaScript | new Intl.DateTimeFormat('en-US', { timeZone: 'Asia/Tokyo', timeStyle: 'short' }).format(date) |
| Python | datetime.now(ZoneInfo('Asia/Tokyo')) |
| Java | Instant.now().atZone(ZoneId.of("Asia/Tokyo")) |
| Go | time.Now().In(time.LoadLocation("Asia/Tokyo")) |
| PostgreSQL | now() AT TIME ZONE 'Asia/Tokyo' |
Need to check a value quickly? Paste it into the Unix timestamp converter.