DevTools Logo

Timestamps & Timezones Cheat Sheet

Quick reference for time handling: ISO 8601, Unix timestamps, UTC, offsets, DST, and formatting patterns across languages.

Reference
timestamp
timezone
utc

Most time bugs come from confusing instants (absolute moments in time) with local representations. The rules: store instants in UTC, communicate in ISO 8601 with an offset, and only convert to a local timezone at the display boundary.

ISO 8601 — The Wire Format

Table
FormExample
UTC (Z)2026-08-11T14:30:00Z
With offset2026-08-11T14:30:00+03:00
Date only2026-08-11
Date + time, no zone2026-08-11T14:30:00 (ambiguous — avoid)
Week date2026-W33-2
Ordinal date2026-223

Always communicate with an explicit offset or Z. A bare 2026-08-11T14:30:00 without a zone is ambiguous across systems.

Unix Timestamps

Unix time counts seconds since 1970-01-01T00:00:00Z (UTC). It is timezone-independent — the same number is the same instant everywhere.

js
Date.now() / 1000            // seconds (float)
Math.floor(Date.now() / 1000)
new Date(1780000000000)      // ms → Date
python
import time, datetime
time.time()                                    # seconds
datetime.datetime.fromtimestamp(1780000000, tz=datetime.timezone.utc)
Table
PrecisionRangeUse
Seconds1780000000Common API default
Milliseconds1780000000000JS Date.now()
Microseconds1780000000000000Python datetime
Nanoseconds1780000000000000000Go, Rust SystemTime

UTC, Offsets, and DST

Table
TermMeaningExample
UTCThe reference time, no offset14:30:00Z
OffsetFixed difference from UTC+03:00, -05:00
IANA timezoneRegion-based rules incl. DSTEurope/Istanbul, America/New_York
DSTSeasonal clock shift+03:00 in summer, +02:00 in winter

Never store a fixed offset as "the timezone." Offsets change with DST; IANA names encode the rules. +03:00 is not Europe/Istanbul.

python
# IANA-aware (stdlib from 3.9+)
from zoneinfo import ZoneInfo
now = datetime.datetime.now(ZoneInfo("Europe/Istanbul"))
js
const date = new Date();
console.log(date.toLocaleString("en-US", { timeZone: "Europe/Istanbul" }));

Formatting Patterns

js
// JS
new Date().toISOString();                       // 2026-08-11T14:30:00.000Z
new Intl.DateTimeFormat("en-GB", { dateStyle: "medium", timeStyle: "short", timeZone: "UTC" }).format(new Date());
python
# Python strftime
datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
Table
CodeMeaningOutput
%Y-%m-%d / YYYY-MM-DDDate2026-08-11
%H:%M:%S / HH:mm:ssClock14:30:00
%z / +03:00ISO offset+0300 / +03:00
%ZZone nameUTC, EEST
%sUnix seconds1780000000

Common Pitfalls

[!WARNING] Never do arithmetic on wall-clock times across DST boundaries. Treat 2026-03-29 02:30 in a DST zone as potentially nonexistent/ambiguous — parse to UTC first, then render.

[!TIP] Store everything in UTC internally; use IANA timezone names in config, not fixed offsets; format for humans only at the very last step.

References