Home › Developer Tools › Strftime Format Builder

Strftime Format Builder

Build a strftime format string for Python's datetime or C's time.h by clicking tokens instead of memorising them. The preview updates as you type, each part of the format is explained, and the tool warns when a directive or flag will not work on Windows, macOS or glibc.

Last updated:

Output
Click a token to insert it at the cursor
Common formats
What your format means
Code

    
Advertisement
Advertisement

How to use the Strftime Format Builder

  1. Pick your language and platform: Python on Linux/macOS, Python on Windows or C with glibc.
  2. Click tokens in the palette to insert them at the cursor, and add separators with the small buttons or by typing.
  3. Check the output at the top. Change the preview date or switch between local time and UTC to test edge cases.
  4. Read the warnings: they flag codes that fail or behave differently on the selected platform.
  5. Copy the format or the generated code into your project.

Strftime reference

Examples use Saturday, March 7, 2026 at 14:05:09.123456 in UTC (C locale, English names). The last column shows where each directive works.

CodeMeaningExampleWorks on
%YYear with century2026All
%yYear without century26All
%mMonth number, zero-padded03All
%B / %bFull / abbreviated month nameMarch / MarAll
%dDay of month, zero-padded07All
%eDay of month, space-padded 7All (Windows via the modern C runtime)
%jDay of the year066All
%A / %aFull / abbreviated weekdaySaturday / SatAll
%w / %uWeekday number, Sunday = 0 / ISO, Monday = 16 / 6All
%U / %WWeek of year, Sunday / Monday first09 / 09All
%G-W%VISO week-based year and week2026-W10All
%H / %IHour, 24-hour / 12-hour clock14 / 02All
%pAM or PMPMAll
%M / %SMinute / second05 / 09All
%fMicroseconds123456Python only
%zUTC offset+0000All (Python: aware datetimes only)
%:zUTC offset with colon+00:00Python 3.12+
%ZTime zone nameUTCAll (Python: aware datetimes only)
%F / %TShortcuts for %Y-%m-%d / %H:%M:%S2026-03-07 / 14:05:09All
%k / %l / %PSpace-padded 24h / 12h hour, lowercase am/pm14 /  2 / pmglibc and Python on Linux (%P not on macOS)
%sSeconds since 1970-01-01 UTC1772892309glibc, macOS; not Windows
%%A literal percent sign%All

Padding flags and portability

A flag between the % and the letter changes the padding. They are extensions to the C standard, so support depends on the platform:

  • %-d: no padding (7). glibc, macOS and Python on those systems.
  • %_d: pad with spaces ( 7). glibc.
  • %^a: uppercase (SAT). glibc only.
  • %#d: no padding on Windows. On glibc the # flag swaps letter case instead.

If one script must run on Linux, macOS and Windows, avoid the flags and build the unpadded number in code, or use a library such as Babel or Arrow. In Python, f-strings accept the same codes, so f"{dt:%Y-%m-%d}" is the same as dt.strftime("%Y-%m-%d").

Choosing a format

  • Machine-readable data: ISO 8601 (%Y-%m-%dT%H:%M:%S%z) sorts correctly as text and is understood by almost every parser.
  • File names: %Y%m%d_%H%M%S has no colons or slashes, which are not allowed in Windows file names.
  • HTTP headers and cookies: always format in UTC and write the literal GMT, as in %a, %d %b %Y %H:%M:%S GMT.
  • People: spell the month (%B %d, %Y) to avoid the 03/07 versus 07/03 ambiguity between US and European readers.

Need to convert an existing date between formats, or translate a pattern to moment.js or Java syntax? Use the Date Format Converter. For epoch values, see the Unix Timestamp Converter.

Frequently asked questions

What is strftime?

strftime (string format time) is the C standard library function that turns a date and time into text according to a format string. Python's datetime.strftime(), time.strftime(), PHP's strftime(), Ruby's Time#strftime and many logging tools use the same % directives, such as %Y for a four-digit year and %H for the hour.

How do I remove the leading zero from the day or hour in Python?

On Linux and macOS use a dash after the percent sign: %-d gives 7 instead of 07 and %-I gives 3 instead of 03. On Windows that raises ValueError; use %#d and %#I instead. For code that must run everywhere, format the number yourself, for example f"{dt.day}" or str(dt.hour).

What is the difference between %U, %W and %V?

%U counts weeks starting on Sunday and %W counts weeks starting on Monday; days before the first Sunday or Monday of the year are in week 00. %V is the ISO 8601 week number (01-53), where week 1 is the week containing the year's first Thursday. Pair %V with %G, the ISO week-based year, not %Y.

Why are %z and %Z empty in my Python output?

The datetime is naive, meaning it has no tzinfo. Python only fills %z and %Z for aware datetimes. Create one with datetime.now(timezone.utc) or datetime.now().astimezone(), or attach a zone with zoneinfo.ZoneInfo.

Does C strftime support microseconds?

No. %f is a Python addition; C's struct tm has no field smaller than a second. In C, get sub-second precision with clock_gettime() and append the fraction yourself.

Why does %c look different on Windows?

%c, %x and %X use the current locale. In the default C locale, glibc prints %c like 'Sat Mar 7 14:05:09 2026', while the Windows runtime prints '03/07/26 14:05:09'. Use an explicit format such as %Y-%m-%d %H:%M:%S when the exact output matters.

Can I use the same format to parse a date with strptime?

Usually yes: datetime.strptime(text, format) accepts the same codes for the common directives. It does not accept the padding flags (%-d) or shortcuts like %F, %T and %e, so the tool tells you which parts to rewrite before parsing.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

Date Format ConverterConvert any date to ISO 8601, RFC 2822, Unix time and custom strftime, moment or Java patterns.Unix Timestamp ConverterConvert epoch timestamps to dates and back.Cron Expression GeneratorBuild crontab schedules visually, read them in plain English and see the next run times.Regex TesterTest and debug regular expressions live.JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.SQL Formatter & BeautifierFormat, beautify or minify SQL queries for MySQL, PostgreSQL and more.JavaScript BeautifierFormat and beautify messy or minified JavaScript, or minify it.HTML FormatterBeautify and indent HTML code with a live preview.CSS FormatterBeautify CSS with indent controls and optional property sorting.XML FormatterBeautify, validate and minify XML with a collapsible tree view.ZIP File CreatorCompress files and folders into a ZIP.YAML Validator & FormatterValidate, format and minify YAML, and convert YAML to JSON or back.HTML MinifierMinify HTML: strip comments and whitespace safely and see how many bytes you save.CSS MinifierMinify CSS with csso or a built-in engine and see the size saved instantly.JavaScript MinifierMinify JavaScript with Terser: compress, mangle and see how many bytes you save.JSON MinifierMinify and validate JSON, sort keys and see exactly how many bytes you save.Code Diff CheckerCompare two code files side by side or unified, with syntax colors and changes highlighted.IPv6 Expander & CompressorExpand IPv6 addresses to full form or compress them per RFC 5952, one or many at once.GraphQL FormatterPretty-print and indent GraphQL queries, mutations and schemas, or minify them, instantly.CSS ValidatorValidate CSS: syntax errors, unknown properties and invalid values by line, plus auto-fix.Gzip Compress / DecompressGzip or deflate text and files, get Base64 output, and decompress Base64 or .gz files.IBAN ValidatorCheck an IBAN's mod-97 checksum, country and length, and see its bank code and account parts.JavaScript Syntax CheckerCheck JavaScript for syntax errors with line and column, for any ES version, script or module.JSON Schema ValidatorValidate JSON against a JSON Schema (draft-07, 2019-09, 2020-12) with clickable error paths.Markdown FormatterBeautify Markdown with Prettier: list markers, prose wrap, aligned tables and live preview.PHP FormatterBeautify PHP code with Prettier PHP: PSR-12 style, indent and brace options, syntax errors.TypeScript FormatterFormat TypeScript and TSX code with Prettier: width, tabs, semicolons and quotes options.XML MinifierMinify and validate XML: strip whitespace and comments, keep CDATA, see the size savings.C# FormatterBeautify C# code online: Allman or K&R braces, indent size and line width, clang-format option.HTML ValidatorCheck HTML for errors and warnings with line numbers, locally or with the W3C Nu checker.Java FormatterBeautify Java code online: indent size, brace style and line width, with clang-format option.JavaScript ObfuscatorObfuscate JavaScript with string encoding, renaming and control-flow flattening presets.Phone Number FormatterFormat and validate lists of phone numbers to E.164, international or national style.Python FormatterFormat Python code in Black/Ruff style: line length, quote style, indent, copy or download.Responsive Design CheckerPreview any website at phone, tablet, laptop and desktop sizes side by side, with rotate and zoom.Browser Compatibility CheckerSearch CSS, JavaScript and HTML features and see which browser versions support them.Core Web Vitals CheckerCheck real-user LCP, INP and CLS for any URL or site and see if it passes Core Web Vitals.Heading Structure CheckerPaste HTML to see its H1-H6 outline and catch missing H1s, multiple H1s and skipped levels.Routing Number ValidatorCheck a US ABA routing number's checksum and format and see its Federal Reserve district.Spam Word CheckerScan an email subject and body for spam trigger words, excess caps, exclamation marks and risky links.Check Digit CalculatorCalculate or validate check digits for UPC, EAN, GTIN, SSCC, ISBN, ISSN and mod 11 codes.Luhn Algorithm CheckerValidate numbers with the Luhn mod 10 check or calculate the missing check digit, step by step.XSD ValidatorValidate XML against an XSD schema in your browser and see each error with its line number.Website Hosting CheckerFind out who hosts a website: hosting provider, IP addresses, ASN, network owner and location.
See all 41 Code Formatters & Validators →