Date Pattern Tester & Translator

Test a date format pattern live, see each code explained, and translate it between Java, Python, .NET, date-fns, PHP and SQL.

Runs in your browser. Nothing is uploaded.

Result

    What each code means

    CodeMeaningResult

    The same pattern in other languages

    LanguagePatternCopy
    Java (DateTimeFormatter)

    JavaScript (date-fns)

    JavaScript (Moment.js, Day.js)

    C# / .NET

    Python (strftime)

    PHP (date)

    SQL: MySQL / MariaDB (DATE_FORMAT)

    SQL: PostgreSQL / Oracle (TO_CHAR)

    How to use the Date Pattern Tester & Translator

    1. Choose the Language your pattern is written for, such as Java, Python or PostgreSQL.
    2. Type or paste the pattern. The Result updates as you type, using the current date and time.
    3. Change Date and time or Time zone to test a specific moment, such as New Year's Eve or a date with a single-digit day.
    4. Read the table to see what each code means, and fix anything flagged in the warnings.
    5. Copy the same pattern in another language from The same pattern in other languages.

    One date, many dialects

    Every language formats dates with a pattern string, but the letters mean different things. In Java MM is the month and mm the minutes, while %M is minutes in Python but the month name in MySQL. DD is the day of the month in Moment but the day of the year in Java and date-fns. Copying a pattern from one language into another, or from an answer online, is a common source of dates that look almost right.

    Test before you ship

    This tester runs your pattern on a real date as you type. The table below the result splits the pattern into codes, says what each one means and shows what it printed, so it is easy to spot the code that went wrong. Common mistakes are flagged as warnings: minutes where the month was meant, the week-based year instead of the calendar year, a 12-hour clock without AM/PM, PostgreSQL’s HH being the 12-hour clock, or text that needs quotes.

    Pick a different date and time zone to test edge cases: single-digit days and months (does d give 4 or 04?), afternoon times, the last days of December, and offsets such as UTC+05:30. The offset and zone abbreviation follow the zone’s real rules, including daylight saving time.

    Translate a pattern

    The lower table shows the same pattern in Java (DateTimeFormatter), JavaScript (date-fns, Moment.js and Day.js), C# / .NET, Python (strftime), PHP (date), MySQL (DATE_FORMAT) and PostgreSQL / Oracle (TO_CHAR). Literal text is quoted the way each language expects ('T', [T], \T or "T"), and anything a language can’t express is listed so you know what to handle in code. Switching the Language menu translates the pattern you typed into the new language.

    For a complete list of codes per language, see the Date Format Cheat Sheet.

    Frequently asked questions

    Why does my date show minutes where the month should be?

    In Java, date-fns, Moment and .NET, mm means minutes and MM means month. A pattern like yyyy-mm-dd prints the minutes in the middle. The tester warns about this and shows the right code.

    Why does YYYY give the wrong year at the end of December?

    In Java and date-fns, YYYY is the week-based year used with ISO week numbers. From about 29 December it can already be next year. Use yyyy for the calendar year.

    What happens to codes that don't exist in the other language?

    They are left out of the translated pattern and listed under it, for example milliseconds in Python's strftime, which only has 6-digit microseconds (%f).

    Are month and weekday names translated?

    Names are shown in English, the default of every library here. In your code, the locale you pass (or the system locale) decides the language.

    Why do some Python codes say Linux and macOS only?

    Codes like %-d (day without a leading zero) come from the C library, not Python. Windows uses %#d instead.

    Tutorials