Date Pattern Tester & Translator · Tutorial
How to fix a date pattern showing minutes as the month
4 min readbeginnerUpdated
Your app prints 2026-07-04 for 4 March, and the middle number changes every time you refresh. The pattern uses mm (minutes) where it needs MM (month). You'll see the mistake in the tester, fix it, and check the result on an awkward date.
What you need
- The Date Pattern Tester
- The pattern from your code (the Try it button loads the faulty one)
Steps
Paste the pattern
Choose Java (DateTimeFormatter) under Language and paste the pattern. For 4 March 2026 at 15:07 the result is
2026-07-04 15:07, with the minutes in the month's place.yyyy-mm-dd HH:mmRead the code table
The table lists
mmas Minute, 2 digits, not the month. The same letters mean the same in date-fns, Moment and .NET.Fix the pattern
Change the first
mmtoMM. The result becomes2026-03-04 15:07.yyyy-MM-dd HH:mmTest an edge case
Set Date and time to 31 December at 23:59 and check that the year, month and day are still right. If you had used
YYYY, the tester would warn that it is the week-based year.
Try it yourself
Opens the Date Pattern Tester & Translator with this tutorial's sample loaded.
Common mistakes
- Fixing only one mm
- The pattern needs
MMfor the month andmmfor minutes. Swapping both just moves the problem. - Mixing up DD and dd
- In Java and date-fns,
DDis the day of the year. Useddfor the day of the month. - Lower-case hh without AM/PM
hhis the 12-hour clock. UseHHfor 24-hour time, or addafor AM/PM.
Next steps
Go back to the Date Pattern Tester & Translator, or keep going with one of these: