Quick revision
The short answer
A DateTimeFormatter parses in two phases: it reads the text into fields, then resolves the fields into a date, and the ResolverStyle decides how strict the second phase is. SMART, the default for ofPattern, turns 2023-02-30 into 2023-02-28, STRICT rejects it (and with STRICT we must use uuuu, because yyyy needs an era), and LENIENT rolls it over to 2023-03-02. Text such as month names uses the formatter's locale, so we set it explicitly, and for APIs we use ISO formatters, which are strict.
What to remember
In this answer, we saw that DateTimeFormatter first parses text into fields, using the locale for text such as month names, and then resolves the fields according to its ResolverStyle. SMART, the default for ofPattern, adjusts 2023-02-30 to 2023-02-28; STRICT rejects it, and needs uuuu instead of yyyy because year of era requires an era; LENIENT rolls it over to 2023-03-02. For APIs, we use the strict ISO formatters and explicit locales, so bad input is rejected instead of silently changed.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A DateTimeFormatter parses in two phases: it reads the text into fields, then resolves the fields into a date, and the ResolverStyle decides how strict the second phase is. SMART, the default for ofPattern, turns 2023-02-30 into 2023-02-28, STRICT rejects it (and with STRICT we must use uuuu, because yyyy needs an era), and LENIENT rolls it over to 2023-03-02. Text such as month names uses the formatter's locale, so we set it explicitly, and for APIs we use ISO formatters, which are strict.
Why this question is asked
Parsing dates looks like a solved problem until invalid input arrives. A partner sends 2023-02-30, and depending on how a formatter was built, our service either stores 28 February, stores 2 March, or rejects the request. All three behaviours exist in java.time on purpose, and interviewers ask about them to see whether we know which one we are getting by default. In this answer, we will recap how a formatter parses, see how the locale affects text fields, walk through the three resolver styles with 2023-02-30, look at the yyyy versus uuuu trap, and settle on a choice for APIs.
1A Quick Recap: Parsing Happens in Two Phases
When we call LocalDate.parse(text, formatter), the formatter works in two phases. In the first, parsing, it reads the text according to the pattern and collects raw field values: year 2023, month 2, day 30. At this point nothing checks whether those values make a real date.
In the second, resolving, it combines the fields into a date and validates them. February has 28 days in 2023, so day 30 is a problem, and the resolver style decides what happens: adjust, reject or roll over. The locale and the resolver style are two separate settings that act in these two phases.
- Read text with the patternuses the locale for names like 'mars'
- Collect raw fieldsyear 2023, month 2, day 30
- Resolve with ResolverStyleSTRICT, SMART or LENIENT
- Valid date?YesReturn LocalDateNoAdjust, reject or roll over, per style
4 steps in order. Play them, or step through them one at a time.
2Locale: Which Language the Text Fields Use
Patterns that contain text, such as MMMM for the full month name or EEE for the day name, use the formatter's locale both when formatting and when parsing. DateTimeFormatter.ofPattern(pattern) without a locale takes the JVM's default formatting locale, which differs between a developer's laptop, a CI server and a container. So the same code can parse 'March' on one machine and fail on another.
So we always pass the locale, either in ofPattern or with withLocale, instead of relying on the default. For machine data we avoid text fields entirely and use numbers.
3SMART, STRICT and LENIENT With 2023-02-30
Now the three resolver styles, all with the same pattern and the same invalid input. We use uuuu here, for a reason explained in the next section.
| Input | STRICT | SMART (default) | LENIENT |
|---|---|---|---|
| 2023-02-28 | 2023-02-28 | 2023-02-28 | 2023-02-28 |
| 2023-02-30 | error | 2023-02-28 | 2023-03-02 |
| 2023-02-32 | error | error | 2023-03-04 |
| 2023-13-01 | error | error | 2024-01-01 |
SMART is the default for ofPattern, and it tries to be helpful. For ISO dates, if the day is in the general range 1 to 31 but too large for the month, it is adjusted to the last valid day, so February 30 becomes February 28. Values outside the general range, such as day 32 or month 13, are still rejected.
STRICT rejects anything that is not a real date. LENIENT goes the other way: it treats overflow as arithmetic, so February 30 is two days after February 28, which is March 2, and month 13 of 2023 is January 2024. Notice that SMART and LENIENT both return a date that the sender never wrote, silently.
4The yyyy Trap Under STRICT
A common surprise is that switching to STRICT with the familiar yyyy pattern breaks even valid dates.
The reason is that y means year of era, a year counted within an era such as AD or BC. Without an era field, a strict resolver refuses to guess which era 2023 belongs to, so it cannot build a date. SMART quietly assumes the current era, which is why yyyy works by default. u is the proleptic year, a single continuous count with year 0 and negative years, so it needs no era. That is why java.time code that uses STRICT always writes uuuu.
5What We Use for APIs
For data exchanged between systems, silently changing a date is worse than rejecting it. A partner who sends February 30 has a bug, and storing February 28 or March 2 hides that bug in our data. So for APIs we use the predefined ISO formatters, such as DateTimeFormatter.ISO_LOCAL_DATE and ISO_OFFSET_DATE_TIME, which are already STRICT and have no locale-dependent text. LocalDate.parse(text) with no formatter uses ISO_LOCAL_DATE too. If a custom pattern is unavoidable, we build it with uuuu, set ResolverStyle.STRICT and an explicit locale, and return a clear 400 error that names the field.
6Follow-up questions
Is SMART ever the right choice?
For human input in a user interface, sometimes, because adjusting an obviously close value can be friendlier. Even then it is usually better to reject the value and show the user a message, since they may have meant something else. For machine data, no.
Where does SimpleDateFormat fit in this picture?
SimpleDateFormat is lenient by default, like ResolverStyle.LENIENT, so legacy code may have been accepting February 30 as March 2 for years. setLenient(false) makes it strict. When migrating to DateTimeFormatter, tests with invalid inputs reveal which behaviour callers depended on.
Why does the default locale matter for numeric patterns?
Mostly it does not for digits in patterns like uuuu-MM-dd, but the locale also controls things like week definitions for Y and w, and the AM/PM text for a. Passing an explicit locale everywhere removes a whole class of environment-dependent behaviour.
7Conclusion
In this answer, we saw that DateTimeFormatter first parses text into fields, using the locale for text such as month names, and then resolves the fields according to its ResolverStyle. SMART, the default for ofPattern, adjusts 2023-02-30 to 2023-02-28; STRICT rejects it, and needs uuuu instead of yyyy because year of era requires an era; LENIENT rolls it over to 2023-03-02. For APIs, we use the strict ISO formatters and explicit locales, so bad input is rejected instead of silently changed.
Open with
A DateTimeFormatter parses in two phases. First it reads the text into fields according to the pattern, and for text fields like full month names it uses the formatter's locale, so I always set the locale explicitly with ofPattern or withLocale instead of relying on the JVM default.
Then, if they want more
Then it resolves the fields into a date, and the ResolverStyle decides what happens with invalid combinations. SMART is the default for ofPattern: for a day that is in the range 1 to 31 but too large for the month, it adjusts to the last valid day, so 2023-02-30 becomes February 28th, though day 32 is still rejected.
STRICT rejects February 30th outright. With STRICT I have to use uuuu instead of yyyy, because y is year of era, and a strict resolver won't assume an era, so even valid dates fail with yyyy. LENIENT treats overflow as arithmetic, so February 30th rolls over to March 2nd in a non-leap year.
For APIs I use the ISO formatters like ISO_LOCAL_DATE, which are strict and locale-free, so bad input gets a clear error instead of being silently changed into a date the sender never wrote.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How does DateTimeFormatter handle locale and resolution? Explain ResolverStyle STRICT...": https://scrivio-interview-library.netlify.app/java/date-and-time/fe398fc03a/