Date Format String Builder
Type a sample such as "2026-10-19 15:04:05" and get matching format strings for strftime (C, Python, Ruby), Java DateTimeFormatter, PHP date(), Day.js / Moment.js, and .NET ToString at once. You can also translate an existing format string into the other syntaxes. To convert between epoch time and dates, use the Unix Timestamp Converter; for counting days, try the Date Calculator.
🔒 Runs in your browser · Your data is never sent to a server
Build a format from a sample
Enter any text containing a date or time. Digits, English month and weekday names, and AM/PM are recognized and turned into a format.
Convert a format string
Preview (current date and time):
Format strings by language
Build a format from a sample
- strftime (C, Python, Ruby)
- Java (DateTimeFormatter)
- PHP (date)
- JavaScript (Day.js, Moment.js)
- .NET (ToString)
Convert a format string
- strftime (C, Python, Ruby)
- Java (DateTimeFormatter)
- PHP (date)
- JavaScript (Day.js, Moment.js)
- .NET (ToString)
How to use
- Type a sample date such as 2026-10-19 15:04:05 into "Sample date and time".
- Format strings for each language appear; press "Copy" next to the one you need.
- To translate an existing format string, pick "Source format type" and enter it in "Format string".
Notes
- Detection from a sample is a best guess. For an ambiguous date such as 03/04/2026, slashes are read as month/day and dots as day.month.
- strftime %-d and %-m (no padding) are Linux, macOS and Ruby extensions; the Windows C runtime writes %#d instead. %L for milliseconds is Ruby, while Python's %f means microseconds (6 digits).
- Items a syntax has no specifier for (the day of year in PHP, the +0900 style in .NET, and so on) are left out, and a message says so.
- In .NET, / and : are replaced by the culture's date and time separators at runtime. Escape them as \/ and \: to keep them fixed.
- Month and weekday names are English only. Localized names are not part of the format string.
Glossary
strftime
A date and time format that originated in C. It writes specifiers as a percent sign plus a letter, such as %Y or %m, and is shared by Python, Ruby, the shell date command, and many other environments.
DateTimeFormatter (Java)
The Java 8+ date and time formatter. Repeated letters set the width (yyyy, MM, dd), and case matters: MM is the month while mm is the minute.
Case sensitivity
In Java and .NET, MM is the month, mm the minute, HH the 24-hour hour, and hh the 12-hour hour. Mixing them up produces garbled dates, so check these first when converting.
ISO 8601
The international notation for dates and times, such as 2026-10-19T15:04:05+09:00. It writes the date, the time, and the UTC offset in a fixed order.
FAQ
What is the difference between MM and mm, or HH and hh, in Java?
Case changes the meaning. MM is the month, mm is the minute, HH is the 24-hour hour (0-23), and hh is the 12-hour hour (01-12). Writing yyyy-mm-dd puts the minute where the month should be. strftime follows the same idea: %m is the month, %M the minute, %H the 24-hour hour, and %I the 12-hour hour.
Is 03/04/2026 read as March 4 or April 3?
When both numbers are 12 or less, the order cannot be known, so the tool guesses: slashes are read as month/day/year (US style) and dots as day.month.year (European style), and it tells you it guessed. A date like 19/04/2026 is unambiguous because 19 cannot be a month. If the guess is wrong, edit the format string in the field below.
Why does the no-padding %-d not work on Windows?
%-d and %-m are glibc (Linux), macOS, and Ruby extensions; the Windows C runtime does not support them and uses %#d instead. Python defers to the C library of the OS it runs on, so the same code can behave differently by platform. If portability matters, format the value with an f-string or similar instead of strftime.
Can I use milliseconds and time zones in every syntax?
Milliseconds are SSS in Java, v in PHP, SSS in Day.js / Moment.js, and fff in .NET. strftime has no standard millisecond specifier; Ruby offers %L, while Python's %f is microseconds (6 digits). The +09:00 style offset is XXX in Java, P in PHP, Z in Day.js / Moment.js, zzz in .NET, and %:z in strftime. Anything without an equivalent is left out and listed on the page.
How do I include a literal T or other letters in a format?
Letters that have a meaning in the format must be quoted to print as-is. Java and .NET use single quotes such as 'T', PHP uses a backslash such as \T, and Day.js / Moment.js use square brackets such as [T]. strftime prints anything outside a %-specifier as written, so no quoting is needed (a literal % is written %%). The tool applies the right escaping automatically when it converts.
Share this page
