Guide
Building date format strings with strftime directives
The strftime function formats a date and time from a pattern full of percent codes: %Y for the year, %m for the month, %H for the hour. It was born in the C library and is now found in Python, Ruby, PHP, the Unix date command and many other tools, with small differences between them. This page lets you try a pattern against a real date, see what each directive contributed and pick up the extras that people forget.
How a pattern is read
Everything that is not a percent sign is copied through. A percent sign followed by a letter is a directive, replaced by the matching part of the date. %Y is the four-digit year, %y the two-digit one, %m the month number from 01 to 12, %d the day from 01 to 31, %H the 24-hour hour, %I the 12-hour hour with %p for AM or PM, %M the minute and %S the second. %A and %B give the full weekday and month names, %a and %b the short ones. A doubled %% produces a literal percent sign.
Flags and padding
GNU libc and the tools built on it allow a flag between the percent sign and the letter. A hyphen removes padding, so %-d gives 5 and not 05. An underscore pads with a space, %_d giving “ 5”, and a zero forces zero padding. A caret writes the result in upper case, so %^a gives FRI. These flags are not part of the C standard, so portable programs avoid them or check the platform, but they are widely useful in shell scripts and Python on Linux and macOS.
Weeks and the ISO year
Week numbers are a common trap. %U numbers weeks from the first Sunday, %W from the first Monday, and %V follows ISO 8601 where week 1 is the week with the first Thursday of the year. Because the ISO week can belong to the previous or next calendar year, there is a matching year, %G. Use %G only with %V; mixing %Y with %V labels 29 December 2025 as 2025-W01, although that day belongs to week 1 of 2026. The pattern %G-W%V-%u gives the ISO week date.
Time zones
Choose the device’s zone, UTC, a fixed offset such as +05:30, or a named zone such as Asia/Tokyo. %z prints the numeric offset, for example +0000 or +0900. %Z prints a zone name, which the browser supplies; for some zones that is an abbreviation such as UTC and for others a form like GMT+9 rather than JST, because abbreviations are not standardised. Prefer %z in machine-readable output.
A worked example
For the instant 2026-10-30 14:05:09 UTC, the ISO 8601 preset %Y-%m-%dT%H:%M:%S%z gives 2026-10-30T14:05:09+0000. The log preset %d/%b/%Y:%H:%M:%S %z gives 30/Oct/2026:14:05:09 +0000, as in web server access logs. %A, %B %-d, %Y gives Friday, October 30, 2026, and the US pattern %m/%d/%Y %I:%M %p gives 10/30/2026 02:05 PM. The week date %G-W%V-%u gives 2026-W44-5, and in Tokyo, %Y-%m-%d %H:%M %Z gives 2026-10-30 23:05 GMT+9.
Limits
The page models the directives of POSIX with the GNU flags. Names of days and months are always in English, whatever the language of your device. Some languages add their own directives, for example Python’s %f for microseconds or Ruby’s %L for milliseconds; check the documentation of your language for those. The result is formatted in the browser from the date you give, so it matches your code only if the code uses the same zone.
Related tools
- Timestamp Converter converts Unix times to readable dates.
- RFC 3339 Converter rewrites a timestamp in many standard formats.
- ISO 8601 Duration Calculator works with durations rather than points in time.
- Cron Expression Parser explains schedules and their next run times.
Checked against the current version of the strftime Builder on .

