1 year ago

#148633

test-img

Kiril Raykov

Unable to parse input date containing abbreviated asian components using DateTimeFormatter

I'm trying to parse a date string to LocalDate or LocalDateTime (actually any Temporal object), which contains asian abbreviated parts. When I provide a valid abbreviated chinese component(in example below - dayOfMonth), I get DateTimeParseException. Note that for the same scenario for other languages, this works just fine.

Examples:

LocalDate.parse("2022年2月12日 週六", DateTimeFormatter.ofPattern("y年M月d日 EE", Locale.TRADITIONAL_CHINESE)) returns error Text '2022年2月12日 週六' could not be parsed at index 10.

However, if we use the non-abbreviated version (2022年2月12日 星期六), everything works fine.

If we take similar input in Spanish for example: LocalDate.parse("sáb. 12 feb. 2022", DateTimeFormatter.ofPattern("EE. dd MMM. y", Locale.forLanguageTag("es-ES"))), it will parse as expected.

Notes: I'm taking the abbreviated components from the standard CLDR data.

Is it at all possible to parse this input using any standard library?

java

datetime

parsing

localdate

chinese-locale

0 Answers

Your Answer

Accepted video resources