WorldClockDiff

Developer guide: storing dates and time zones correctly

Night Morning / evening Working hours Everyone at work · drag the highlighted column or click an hour

Convert a time

    Developer tools

    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.

    LanguageConvert a UTC instant to a zone
    JavaScriptnew Intl.DateTimeFormat('en-US', { timeZone: 'Asia/Tokyo', timeStyle: 'short' }).format(date)
    Pythondatetime.now(ZoneInfo('Asia/Tokyo'))
    JavaInstant.now().atZone(ZoneId.of("Asia/Tokyo"))
    Gotime.Now().In(time.LoadLocation("Asia/Tokyo"))
    PostgreSQLnow() AT TIME ZONE 'Asia/Tokyo'

    Need to check a value quickly? Paste it into the Unix timestamp converter.