Reference · Time

    Leap seconds

    Earth's rotation isn't constant. Leap seconds keep civil UTC roughly aligned with mean solar time by occasionally inserting an extra second at the end of a UTC day.

    Why they exist

    Atomic time (TAI) ticks uniformly. UTC adds leap seconds so the sun stays near expected clock positions for human calendars. Each leap makes UTC − TAI one second larger until the next adjustment.

    POSIX vs civil UTC

    POSIX time (what most Unix APIs call "Unix time") counts SI seconds since the epoch but does not encode leap seconds as distinct integer values. During a positive leap second, civil clocks show 23:59:60; POSIX timestamps typically repeat or smear that instant depending on OS and ntpd settings. Libraries differ — always document your behavior for audit logs and finance.

    Historical leap seconds (positive)

    #UTC date (end of day insertion)
    11972-06-30
    21972-12-31
    31973-12-31
    41974-12-31
    51975-12-31
    61976-12-31
    71977-12-31
    81978-12-31
    91979-12-31
    101981-06-30
    111982-06-30
    121983-06-30
    131985-06-30
    141988-01-01
    151990-01-01
    161991-01-01
    171992-07-01
    181993-07-01
    191994-07-01
    201996-01-01
    211997-07-01
    221998-01-01
    232005-12-31
    242008-12-31
    252012-07-01
    262015-07-01
    272017-01-01

    Handling leap seconds in code

    Prefer UTC with explicit string formats for human displays; store either POSIX seconds with documented policy, or RFC 3339 strings with offset from an authoritative clock. For log correlation during a leap event, compare monotonic counters plus wall-clock metadata.

    # GNU date: show whether a leap second is scheduled (depends on tzdata)
    TZ=right/UTC date -r @1483228799 +%Y-%m-%dT%H:%M:%S
    # Python 3.9+: aware UTC instant (library may fold leap — check docs)
    from datetime import datetime, timezone
    datetime.fromtimestamp(1483228800, tz=timezone.utc).isoformat()
    Advertisement