Cheat Sheets Development

Date & Time Formats Cheat Sheet

ISO 8601 patterns, strftime codes, Unix time units and the leap-year, week-number and daylight-saving traps, every value produced by running code.

Last reviewed:

AdSense Placeholder
Slot: header_reference_page
On this page

The date and time formats you meet in code, logs and APIs. Every example is for the single instant Saturday October 3, 2026 at 14:30:05 UTC, produced by running the code. Convert with the Date Calculator, Time Duration Calculator and Time Zone Calculator.

ISO 8601, the unambiguous standard

Format Meaning
2026-10-03 Calendar date
2026-10 Year and month
2026-W40-6 Week date: week 40, day 6 (Saturday)
2026-276 Ordinal date: day 276 of the year
14:30:05 Time of day
2026-10-03T14:30:05Z Date and time in UTC (Z means zero offset)
2026-10-03T16:30:05+02:00 The same instant at UTC+2
P1Y2M3DT4H5M6S Duration: 1 year, 2 months, 3 days, 4 hours, 5 minutes, 6 seconds
2026-10-03/2026-10-10 Time interval

Prefer ISO 8601 for storing and exchanging dates: it sorts correctly as text and has one meaning everywhere, unlike 03/10/2026, which is 3 October in most of the world and 10 March in the US. Week dates and week numbers come from the Week Number Calculator; the weekday of any date from the Day of the Week Calculator.

strftime codes

These codes work in Python, C, PHP, Ruby and most shells (a few, such as %e and %f, vary by platform).

Code Meaning Result
%Y year, four digits 2026
%y year, two digits 26
%m month 01 to 12 10
%B month name October
%b month abbreviation Oct
%d day of month 01 to 31 03
%e day of month, space padded 3
%j day of year 001 to 366 276
%A weekday name Saturday
%a weekday abbreviation Sat
%u weekday 1 (Monday) to 7 6
%H hour 00 to 23 14
%I hour 01 to 12 02
%p AM or PM PM
%M minute 00 to 59 30
%S second 00 to 59 05
%f microseconds 000000
%z UTC offset +0000
%Z time zone name UTC
%V ISO week number 40
%G ISO week-based year 2026
%% a literal percent sign %

Unix time

Unit Value for 2026-10-03T14:30:05Z
Seconds (Unix time, most APIs) 1791037805
Milliseconds (JavaScript Date.now()) 1791037805000
Microseconds 1791037805000000
Days since 1970-01-01 20729

Unix time counts seconds since 1970-01-01T00:00:00Z (Unix timestamp). Always say whether a number is in seconds or milliseconds: a 10-digit value is seconds, a 13-digit value is milliseconds.

Pitfalls

  • Leap years. A year is a leap year if divisible by 4, except centuries, unless divisible by 400: 2000 and 2024 are leap years; 1900 and 2100 are not.
  • ISO week years. Dates near New Year can belong to the neighbouring year's week: 1 January 2027 is in week 53 of 2026.
  • Daylight saving time. Local clock times can repeat or not exist for an hour; store UTC and convert for display.
  • Duration versus clock time. Use the Time Calculator for durations in hours and minutes, the Hours Calculator for time-card totals, the Day Counter for days between dates, and the Age Calculator for exact ages. The Military Time Converter and Sleep Calculator cover 24-hour clocks and sleep cycles.

Try these tools

See also

  • Glossary Unix timestamp
    A Unix timestamp is the number of seconds since 00:00:00 UTC on 1 January 1970, the "Unix epoch".
  • Guide How Dates and Time Zones Work
    UTC, offsets and time zones, daylight saving, Unix time and the 2038 problem, leap years, week numbers and day counts.
AdSense Placeholder
Slot: footer_leaderboard