strftime Format Builder
Build and preview date format strings for Python, PHP, Go, and JavaScript.
Format String
Date to Format
| Format | Output | Python |
|---|
Format Codes
The strftime format builder assembles date format strings visually and shows the live output as you type. Switch between Python, PHP, Go, and JavaScript syntax with one click - the same date appears in all four conventions side by side. Useful when you remember the output you want but not the exact format code, or when you are translating a format string from one language to another.
What strftime Is
strftime is a function that takes a date and a format string and returns the formatted date as text. The format string uses percent codes (or letter codes in Go) to represent each piece of the date: %Y for the four-digit year, %m for the two-digit month, %H for the hour, and so on. The same codes work across most languages with minor variations, which is why "strftime format" has become the de facto standard for date formatting.
- Python: strftime() and strptime() use the C-style percent codes.
%Y-%m-%d %H:%M:%Sproduces something like 2026-05-28 14:30:00. - PHP: the date() function uses single-letter codes without the percent prefix.
Y-m-d H:i:sproduces the same output. Note that PHP also has strftime() for percent codes, but date() is preferred in modern code. - Go: uses a reference date instead of codes. The format
2006-01-02 15:04:05represents the layout, and any date you pass replaces those exact numbers with the matching parts. The reference date (Mon Jan 2 15:04:05 MST 2006) is memorable because the numbers go 1 2 3 4 5 6 7. - JavaScript: the built-in Intl.DateTimeFormat uses options objects rather than format strings. Libraries like date-fns expose format() with Unicode tokens (yyyy-MM-dd HH:mm:ss). The builder shows both for comparison.
How the Builder Works
Pick a language tab, then start typing a format string. The Preview box shows the current date and time formatted according to the string, updating live as you edit. Below the input are two tables:
- Date to Format: shows common date outputs (ISO 8601, RFC 2822, US date, European date, time only, year/month, and so on) with the format string that produces each one. Click any row to insert that format into the input.
- Format Codes: the full reference of codes for the selected language. Click any code to insert it into the input at the current position. Each row shows the code, its meaning, and a live example.
The two tables together let you build a format string by clicking instead of typing - useful when you remember the output but not the code. To convert a Unix timestamp into a readable date using a format string, the main converter handles arbitrary timestamps. To produce a Linux date command that uses your format string, the Linux date command generator wraps it in the right invocation for GNU, macOS, or FreeBSD.
When You Need a Format String
Date formatting comes up in almost every backend project, log analysis task, or data pipeline:
- Log filenames: daily backups, rotated logs, and snapshots are commonly named with embedded timestamps like backup-2026-05-28.tar.gz or report_20260528_143000.csv. The format string determines the file name pattern.
- API responses: APIs need to format dates in a consistent way (usually ISO 8601). The builder shows the exact format string that produces ISO 8601 in each supported language.
- Human-readable display: formatting a database timestamp for a UI ("May 28, 2026 at 2:30 PM") requires a specific format string. The builder lets you preview it before committing to the code.
- CSV and report exports: spreadsheet-friendly date formats (MM/DD/YYYY for the US, DD/MM/YYYY for Europe, YYYY-MM-DD for ISO) all have different format strings. The builder shows each side by side.
- Cross-language porting: migrating from Python to Go (or any pair) often requires translating format strings. The builder makes this easy by showing the same date with the same output in all four language conventions.
Common Format Patterns
A few format strings come up so often they are worth memorizing:
- ISO 8601 date:
%Y-%m-%din Python/PHP/strftime,2006-01-02in Go,yyyy-MM-ddin JavaScript libraries. Produces 2026-05-28. - ISO 8601 datetime:
%Y-%m-%dT%H:%M:%Sin strftime,2006-01-02T15:04:05in Go. Produces 2026-05-28T14:30:00. This is the most portable datetime format across systems. - RFC 2822 (email/HTTP headers):
%a, %d %b %Y %H:%M:%S %z. Produces "Thu, 28 May 2026 14:30:00 +0000". Used in email Date headers and the HTTP Last-Modified header. - US-style date:
%m/%d/%Y. Produces 05/28/2026. Common in US spreadsheets and forms. - European-style date:
%d/%m/%Y. Produces 28/05/2026. Common in European countries. - File-safe sortable timestamp:
%Y%m%d_%H%M%S. Produces 20260528_143000. Sorts chronologically as text and contains no characters that conflict with filesystems.
For a recurring schedule based on a date pattern (every Monday, every first of the month), the cron expression builder generates the matching cron expression. To compute a date for a future or past offset, the date add/subtract calculator handles the math.
Frequently Asked Questions
strftime is a function originally defined in C and the POSIX standard that takes a date and a format string and returns the formatted date as text. The format string uses percent codes like %Y (four-digit year), %m (two-digit month), %d (two-digit day), %H (hour), %M (minute), %S (second). The same codes work across Python, PHP, Ruby, Perl, and most other languages that descend from C conventions.
%Y is the four-digit year (2026), %y is the two-digit year (26). Use %Y for any production code or any output that may be misinterpreted: the two-digit %y is ambiguous (26 could mean 1926, 2026, or 2126) and was the root cause of the Y2K problem. The same uppercase/lowercase convention applies to other codes: %H is 24-hour, %I is 12-hour; %m is two-digit month, %B is full month name.
Go's designers chose a single reference date (Mon Jan 2 15:04:05 MST 2006) as the template, and any date passed to Format() replaces those exact numbers with the corresponding values. The reference date is memorable because the numbers go 1 2 3 4 5 6 7 (month=1, day=2, hour=3 in 12-hour, minute=4, second=5, year=6, timezone offset=7). This avoids memorizing percent codes but requires familiarity with the reference date.
PHP's date() function predates standardization on strftime and uses its own single-letter convention (Y for year, m for month, d for day, H for hour, i for minute, s for second). PHP also supports the percent-based strftime() function for compatibility with C, but date() is the recommended choice in modern PHP. The builder shows both conventions; pick the one that matches the function you are calling.
The ISO 8601 date-time format is YYYY-MM-DDTHH:MM:SS, often with a Z suffix for UTC or a +/-HH:MM offset for local time. The strftime equivalent is %Y-%m-%dT%H:%M:%S (or %Y-%m-%dT%H:%M:%S%z to include the timezone offset). The builder has an ISO 8601 entry in the Date to Format table that you can click to insert the correct format string for the active language.
Use a format that sorts chronologically and contains no characters that conflict with filesystems. The standard choice is %Y%m%d_%H%M%S (or %Y-%m-%d_%H-%M-%S if you prefer separators), which produces something like 20260528_143000. Avoid colons, slashes, and spaces because they have special meaning in some filesystems and shells.
%H is the hour in 24-hour format (00 to 23). %I is the hour in 12-hour format (01 to 12). When using %I, also include %p for the AM/PM marker so the time is unambiguous (%I:%M %p produces 02:30 PM). The 24-hour form is preferred in technical contexts because it has no AM/PM ambiguity and sorts correctly as text.
Use %% (two percent signs in a row) to insert a literal percent character. Anything else following a single % is interpreted as a format code, so %Y-%m-%d 50%% complete renders as 2026-05-28 50% complete. The same escape works in Python, PHP strftime, and most other languages that use percent-based format strings.
Yes for some codes. %A (full weekday name), %B (full month name), %a (abbreviated weekday), and %b (abbreviated month) all change based on the active locale - in a German environment %A returns Donnerstag instead of Thursday. Numeric codes (%Y, %m, %d, %H, %M, %S) are locale-independent. The builder uses your browser's locale, so the preview reflects what the same format string would look like on your system.
JavaScript's built-in Intl.DateTimeFormat uses an options object instead of a format string (you pick year, month, day, hour as separate options). Libraries like date-fns and Day.js add format-string support using Unicode tokens (yyyy-MM-dd HH:mm:ss) which differ slightly from strftime. The builder shows both conventions side by side so you can pick the one that matches your tooling.