DateTimeFormatter
模式"yyyy_'w'w"
無法格式化它已解析的值。DateTimeFormatter可以解析,但不能格式化相同的輸入
val df = DateTimeFormatter.ofPattern("yyyy_'w'w")
df: DateTimeFormatter = Value(YearOfEra,4,19,EXCEEDS_PAD)'_''w'Localized(WeekOfWeekBasedYear,1)
val week = df.parse("2017_w19")
week: temporal.TemporalAccessor = {Year=2017, WeekOfWeekBasedYear[WeekFields[SUNDAY,1]]=19},ISO
df.format(week)
的錯誤是:
java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: YearOfEra
java.time.format.Parsed.getLong(Parsed.java:203)
java.time.format.DateTimePrintContext.getValue(DateTimePrintContext.java:298)
java.time.format.DateTimeFormatterBuilder$NumberPrinterParser.format(DateTimeFormatterBuilder.java:2540)
java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2179)
java.time.format.DateTimeFormatter.formatTo(DateTimeFormatter.java:1746)
java.time.format.DateTimeFormatter.format(DateTimeFormatter.java:1720)
這是爲什麼?
那是什麼語言? Scala呢? (並不是說這對您的問題確實很重要,對於Java工程師來說,這只是一個棘手的問題。)如果您沒有得到有用的答案,可以將它翻譯成Java以便覆蓋更廣泛的讀者。 –