Date Format Converter for strftime, moment, and ISO
Python logs, PHP templates, Java services, and JS frontends each spell a date with a different letter set, so a pattern copied across libraries usually prints the wrong parts. This page moves a format string from one dialect to another, lists the tokens it recognized in the target, and renders both patterns against a date you pick. Everything runs in the tab.
Translate a Format String Between Dialects
Source pattern
Pick the library your current pattern came from and type it exactly as that library expects.
Translated pattern
The target field is the translation output. Editing it by hand updates the checks and sample without re-running the translation.
Sample date
Both renderings use this date and the time zone of your browser.
Target presets
A preset fills the target dialect and pattern with a format that appears on the wire often.
Token reference
Every token the current target dialect understands, with an example against the sample date.
| Token | Meaning | Example |
|---|
How It Works
The translator reads the source pattern token by token. Each recognized letter sequence is matched to a shared meaning, such as four digit year or abbreviated weekday, and that meaning is looked up again in the target dialect letter set. Characters between tokens pass through with the target escaping rules applied, so slashes, colons, commas, and spaces stay in place while the letters change.
Round trips are common in log work. The Apache common log time written as strftime %d/%b/%Y:%H:%M:%S %z becomes DD/MMM/YYYY:HH:mm:ss Z in moment and d/M/Y:H:i:s O in PHP, with the numeric offset carried across in each dialect spelling. The validation line under the target field then lists exactly which tokens survived the trip.
Rendering picks a value for every recognized token from the date in the sample field and prints the result. A token the dialect does not know prints as written, which is a quick way to spot a pattern that needs another pass. Both the source and target lines render on every change, so you can compare the two spellings side by side while you edit.
Before and After
%Y-%m-%d %H:%M:%S YYYY-MM-DD HH:mm:ss D, d M Y H:i:s O %a, %d %b %Y %H:%M:%S %z Use Cases
| Source pattern | From | Result | To |
|---|---|---|---|
| %Y-%m-%d | strftime | YYYY-MM-DD | moment |
| D, d M Y H:i:s O | php | %a, %d %b %Y %H:%M:%S %z | strftime |
| MMMM D, YYYY | moment | F j, Y | php |
| YYYY-MM-DD | iso8601 | %Y-%m-%d | strftime |
Common Mistakes
- Pasting a pattern from one library into another and shipping it as is. The letters still parse, but month names turn into numbers or the printout shows raw tokens.
- Editing the target field by hand and then pressing Translate format, which overwrites the manual fix with a fresh translation of the source.
- Skipping the validation line after a hand edit. A stray letter in a moment or Java pattern shows up there as an error before the code ever runs.
- Leaving words such as at or of bare inside a moment pattern. Those letters read as tokens unless they sit in square brackets.
Best Practices
- Translate after each dialect change so the target pattern always matches the library you picked; the button and both selects run the same path.
- Read the token table for the current target before editing by hand. The example column shows what each token prints against the sample date.
- Reach for a target preset when the format appears on the wire, such as RFC 2822 email dates, HTTP Last-Modified values, or SQL DATETIME columns.
- PHP patterns such as jS F Y print an ordinal day like 22nd. The S marker has no counterpart in the other dialects, so after a translation it arrives as literal text rather than an ordinal suffix.
Frequently Asked Questions
What is a date format string?
A date format string is a pattern where each letter stands for a part of the date, such as a four digit year or a zero padded month. Everything outside the letters is copied out as written. Each library reads its own letter set, so the same letters can mean different parts in different dialects.
Why do moment and PHP disagree about the letter M?
moment uses MMMM for the full month name and M for a bare month number, while PHP uses F for the full name and m for a zero padded number. Copying a pattern from one library into the other usually prints letters instead of dates. Translation walks each recognized token and replaces it with the target dialect equivalent.
Which dialects does the translator cover?
Six of them. strftime as used by Python and the C library, moment as used in JavaScript, PHP date(), Java SimpleDateFormat, .NET custom format strings, and the ISO 8601 profile behind the iso8601 token set. Pick a source and a target, then press Translate format.
What happens to text that is not a token?
Characters such as slashes, colons, commas, and spaces pass through as literal text, with the target dialect escaping rules applied. In moment formats, letters that are not tokens sit in square brackets. In PHP, a backslash escapes the next character. In Java and .NET, quotes wrap a literal run.
How does the sample line get rendered?
The sample reads the date you pick in the sample field, looks up a value for each recognized token, and prints the string. Unknown tokens print as written. Rendering uses the local time zone of your browser, so a numeric offset in the sample follows your machine setting rather than a fixed zone.
Can the tool validate a pattern before I ship it?
Yes. The validation line under the target field lists the tokens the dialect recognized, or the errors it found. Common catches are a lone percent sign in strftime, unescaped letters in moment or Java patterns, and an ISO 8601 pattern with no year token.
Does anything I type get sent to a server?
No. The token tables, presets, and translation functions are bundled with the page. The sample date stays in the tab, and rendering runs in your browser. Closing the page clears every field.