Java 解析工作日不适用于区域设置德语

Java 解析工作日不适用于区域设置德语,java,locale,date-parsing,java-time,Java,Locale,Date Parsing,Java Time,我试图使用java.time.format.DateTimeFormatter来解析时间字符串,但在解析德语短的星期几名称时遇到了问题 给定以下程序 导入java.time.DayOfWeek; 导入java.time.format.DateTimeFormatter; 导入java.time.format.DateTimeFormatterBuilder; 导入java.time.format.TextStyle; 导入java.util.Locale; var locale=locale.f

我试图使用java.time.format.DateTimeFormatter来解析时间字符串,但在解析德语短的星期几名称时遇到了问题

给定以下程序

导入java.time.DayOfWeek; 导入java.time.format.DateTimeFormatter; 导入java.time.format.DateTimeFormatterBuilder; 导入java.time.format.TextStyle; 导入java.util.Locale; var locale=locale.forLanguageTagde; var dtf=新的DateTimeFormatterBuilder .appendOptionalDateTimeFormatter.ofPatterneee .appendOptionalDateTimeFormatter.ofPatterneee .toFormatterlocale; var input1=DayOfWeek.tuday.getDisplayNameTextStyle.FULL,区域设置; var input2=DayOfWeek.tuday.getDisplayNameTextStyle.SHORT\u独立,区域设置; System.out.printfinput:%s,已解析:%s\n,input1,dtf.parseinput1; System.out.printfinput:%s,已解析:%s\n,input2,dtf.parseinput2; 我期望的结果是

input: Dienstag, parsed: {DayOfWeek=2},ISO
input: Di, parsed: {DayOfWeek=2},ISO
但实际上我得到了

input: Dienstag, parsed: {DayOfWeek=2},ISO
Exception in thread "main" java.time.format.DateTimeParseException: Text 'Di' could not be parsed, unparsed text found at index 0
    at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2049)
    at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1874)
    at org.rksm.Main.main(Main.java:22)
请注意,当我将区域设置更改为locale.forLanguageTagen时,它可以工作,并且输出是

input: Tuesday, parsed: {DayOfWeek=2},ISO
input: Tue, parsed: {DayOfWeek=2},ISO

我做错了什么?

虽然在英语中单独使用的日期名称与在日期上下文中使用的名称没有区别,但在德语中,显然是有区别的

模式eee对应于TextStyle.SHORT,而模式ccc对应于TextStyle.SHORT\u STANDALONE。因此,如果您试图用重要的语言解析TextStyle.SHORT_STANDALONE与eee创建的日期名称,解析将失败

对于独立版本来说,ccc是一种可行的方法


提到这一点的文档实际上是在API中,而不是在DateTimeFormatter中。

它是否与德语或德语兼容?请注意,eee代表TextStyle.SHORT,而ccc代表TextStyle.SHORT\u STANDALONE。你试过ccc吗?真的,TextStyle.SHORT\u STANDALONE/ccc是一个不错的选择。如果你把它作为答案贴出来,我会把它标记为答案。非常感谢。确实如此:TextStyle.SHORT提供Di。在我的Java 11上,使用默认设置时,使用点,短字符,不使用点;我怀疑设置系统属性java.locale.providers会改变结果。