Quick revision
The short answer
Since Java 9 the JDK takes locale data from the Unicode CLDR by default, and newer JDKs ship newer CLDR versions, so localised formats can change between Java 17 and 21. The best-known change, from Java 20, is that US English short time formats put a narrow no-break space (U+202F) before AM or PM, so a localised formatter no longer matches a plain space in '3:30 PM'. We make formatting stable with explicit patterns and a fixed locale such as Locale.US or Locale.ROOT, ISO formats for machine data, whitespace normalisation or several formatters for human input, and by checking release notes, since the old COMPAT locale data has been removed in recent JDKs.
What to remember
In this answer, we saw that since Java 9 localised formats come from CLDR, and newer JDKs carry newer CLDR versions. From Java 20, US English short time formats use a narrow no-break space before AM or PM, so a localised parser on Java 21 rejects '3:30 PM' with a plain space. We fixed the parser with an explicit pattern, a fixed locale and whitespace normalisation, and set lasting rules: ISO formats for machine data, explicit patterns with fixed locales and tests for partner formats, localised styles only for display, and a release-note check on every JDK upgrade, since the COMPAT fallback is gone in recent JDKs.
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.
Since Java 9 the JDK takes locale data from the Unicode CLDR by default, and newer JDKs ship newer CLDR versions, so localised formats can change between Java 17 and 21. The best-known change, from Java 20, is that US English short time formats put a narrow no-break space (U+202F) before AM or PM, so a localised formatter no longer matches a plain space in '3:30 PM'. We make formatting stable with explicit patterns and a fixed locale such as Locale.US or Locale.ROOT, ISO formats for machine data, whitespace normalisation or several formatters for human input, and by checking release notes, since the old COMPAT locale data has been removed in recent JDKs.
Why this question is asked
A JDK upgrade is supposed to be safe for code that compiles, so formatting changes come as a surprise: a report column looks slightly different, a snapshot test fails, and a partner integration that has parsed '3:30 PM' for years starts throwing exceptions. Interviewers ask this to see whether we know where Java's locale data comes from and how to write formatting code that does not depend on it. In this answer, we will recap where localised formats come from, reproduce the parser failure, explain what changed, fix the parser in a few ways, and set rules for stable formatting in the future.
1A Quick Recap: Where Localised Formats Come From
When we ask for a localised format, for example DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT) or a month name with a pattern like MMMM, Java does not have the text hard-coded. It looks it up in locale data: tables that say how each locale writes dates, times, month names, AM and PM markers and so on.
Since Java 9, the default source of that data is the Unicode Common Locale Data Repository (CLDR), a shared data set also used by browsers, ICU and mobile platforms. CLDR is updated regularly, and each JDK feature release usually takes a newer version. So an upgrade from Java 17 to Java 21 brings several years of CLDR changes, and any code that formats or parses with localised styles can see different text.
2Reproducing the Failure
Here is a partner integration that parses times with the short localised style for US English. On Java 17 it works; on Java 21 it fails.
Notice the index in the error. Position 4 is the space after '3:30'. The formatter expected a different character there. And when we format, the output looks the same on screen, which is why the change is so confusing. Only inspecting the characters shows the difference.
3What Changed: A Narrow No-Break Space
CLDR version 42, which the JDK adopted in Java 20, changed the US English time patterns to put a narrow no-break space, Unicode U+202F, between the time and the AM or PM marker. Typographically it is a sensible choice: it keeps '3:30' and 'PM' on the same line. But for a parser it is simply a different character from the ordinary space, U+0020, that partners send.
So the bug was not in our code or the partner's. Our code delegated the exact format to locale data, and the locale data changed. Other localised outputs can change in the same way across upgrades, such as abbreviations of month names or the words used in long date formats, so this is a class of problem, not a single quirk.
| Java 17 (older CLDR) | Java 21 (CLDR 42 or later) | |
|---|---|---|
SHORT time, Locale.US | 3:30 PM | 3:30 PM, with U+202F before PM |
| Character before PM | U+0020 space | U+202F narrow no-break space |
| Parse "3:30 PM" with SHORT style | 15:30 | DateTimeParseException at index 4 |
Pattern "h:mm a", Locale.US | 15:30 | 15:30, explicit pattern unaffected |
4Fixing the Parser
The most robust fix for a partner format is to stop depending on locale data for the structure. An explicit pattern spells out every character, including the ordinary space, and a fixed locale controls only the AM and PM text. If the partner's input is human-typed and messy, we also normalise whitespace and case before parsing, or try a small list of formatters in order.
Notice that we still pass Locale.US. The pattern letter a prints and reads the AM or PM marker in the formatter's locale, and Locale.ROOT, the neutral locale, would also produce 'PM', but Locale.US states the intent: this partner writes US-style times. Newer JDKs also relaxed lenient parsing so that a plain space can match other space characters; check your version's release notes before relying on that, because an explicit pattern does not need it.
5Making Formatting Stable Going Forward
The lasting rule is to separate machine data from display. Data exchanged with partners, written to files or stored as text uses ISO-8601, such as 15:30 or 2025-03-10T15:30:00Z, which no locale data can change. Where a partner insists on another format, we write an explicit pattern with a fixed locale, keep it in one place, and cover it with tests that include the exact bytes we expect. Localised styles, ofLocalized..., are for showing text to humans, where a narrow space is an improvement rather than a bug.
For the upgrade itself, we read the JDK release notes for locale data and CLDR changes, and run the full test suite, including snapshot tests of formatted output, on the new JDK before switching. Older JDKs offered a fallback, the java.locale.providers=COMPAT setting, which brought back the pre-Java 9 locale data; it was deprecated and then removed in recent JDKs (it is gone in Java 23 and later), so check your version, and in any case treat it only as a short bridge, never as the fix.
- Is the text read by a machine?YesISO-8601 formatterNoIt is for a person
- Is it a fixed partner format?YesExplicit pattern + fixed locale + testsNoLocalised style in the user's locale
- Upgrading the JDK?read CLDR release notes, run snapshot tests
3 steps in order. Play them, or step through them one at a time.
6Follow-up questions
Why did the JDK switch to CLDR in the first place?
Because CLDR is the industry's shared, actively maintained locale data, covering far more locales than the JDK's own legacy tables, and matching what browsers and other platforms show. The cost is that its updates reach our output when we upgrade.
Does this affect DateTimeFormatter.ofPattern("h:mm a")?
Not for the space, because an explicit pattern writes the characters we put in it. The text of a, the AM and PM markers, still comes from locale data, so in some locales it can differ between versions. That is one more reason to pass a fixed locale and test the exact output.
How would you find every place in a large codebase that could be affected?
Search for ofLocalizedDate, ofLocalizedTime, ofLocalizedDateTime, DateFormat.getDateInstance and similar calls, and for ofPattern calls without an explicit locale. Then classify each as machine data or display. Machine-data uses get explicit or ISO formats; display uses can keep localised styles.
7Conclusion
In this answer, we saw that since Java 9 localised formats come from CLDR, and newer JDKs carry newer CLDR versions. From Java 20, US English short time formats use a narrow no-break space before AM or PM, so a localised parser on Java 21 rejects '3:30 PM' with a plain space. We fixed the parser with an explicit pattern, a fixed locale and whitespace normalisation, and set lasting rules: ISO formats for machine data, explicit patterns with fixed locales and tests for partner formats, localised styles only for display, and a release-note check on every JDK upgrade, since the COMPAT fallback is gone in recent JDKs.
Open with
The likely cause is locale data. Since Java 9 the JDK uses CLDR, the Unicode locale data repository, by default, and each JDK release ships a newer CLDR.
Then, if they want more
In Java 20 the JDK moved to CLDR 42, which changed the US English time formats to use a narrow no-break space, U+202F, before AM and PM.
So a formatter built with ofLocalizedTime for Locale.US now prints a different character that looks identical, and when parsing it expects that character, so the partner's 3:30 PM with a normal space fails at index 4. Other localised text can change in similar ways, which explains the formatting differences in reports.
To fix it, for partner data I'd use an explicit pattern like h:mm a with Locale.US, case-insensitive, so the space is spelled out, and normalise whitespace in the input first, or try a small list of formatters.
Going forward, machine data should use ISO-8601, which no locale data affects, localised styles are only for display, and fixed formats get tests that check the exact output. On every JDK upgrade I'd read the release notes for locale data changes.
The old COMPAT provider used to be a fallback, but it has been removed in recent JDKs, so I'd check our version and not rely on it.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21, Java 17, Java 9, Java 20
- 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 "An upgrade from Java 17 to 21 changes how some formatted times look, and a parser now...": https://scrivio-interview-library.netlify.app/java/date-and-time/e383f327d3/