strftime Format Builder

Build and preview date format strings for Python, PHP, Go, and JavaScript.

Format String

type a format string and see the live preview
Type a format string or click presets above. Click codes in the table below to insert them.
Preview
-

Date to Format

click to use
Format Output Python

Format Codes

Python

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.

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:

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:

Common Format Patterns

A few format strings come up so often they are worth memorizing:

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.