Use one a
As the error describes, you have used too many a
character codes.
Change aa
to a
.
Localization
You may have been thinking of two letters for AM and PM. But actually, other text might appear instead.
The text generated by a
depends on the human language and cultural norms used during localization. You specify the language and norms by way of a Locale
. If omitted, your JVM’s current default locale is implicitly applied.
Example code
For fun, let’s try looking at all possible outputs across all locales.
DateTimeFormatter f = DateTimeFormatter.ofPattern ( "h:mm a" ) ;
LocalTime lt = LocalTime.of( 19 , 0 ) ;
for( Locale locale : Locale.getAvailableLocales() )
{
String s = lt.format( f.withLocale( locale ) ) ;
System.out.println( locale + " : " + s ) ;
}
See this code run live at IdeOne.com.
You can see that many different pieces of text are possible, many are more than two characters. Even those using PM
or pm
may have more than two characters when including FULL STOP character: p.m.
.
nn : 7:00 ettermiddag
ar_JO : 7:00 م
bg : 7:00 сл.об.
kea : 7:00 pm
nds : 7:00 PM
zu : 7:00 PM
am_ET : 7:00 ከሰዓት
fr_DZ : 7:00 PM
ti_ET : 7:00 ድሕር ሰዓት
bo_CN : 7:00 ཕྱི་དྲོ་
hsb : 7:00 popołdnju
qu_EC : 7:00 p.m.
ta_SG : 7:00 பிற்பகல்
lv : 7:00 pēcpusdienā
en_NU : 7:00 PM
…