SOS:
私は、文字列を変換しようとしているWed July 2019 10:53 PM
にLocalDateTime
次のコードを使用してオブジェクト:
String dateAndTimeAsStr = "Wed July 2019 10:53 PM";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE MMMM yyyy h:mm a");
LocalDateTime dateAndTimeAsLocalDateTime = LocalDateTime.parse(dateAndTimeAsStr, formatter);
私はこのコードを実行すると、まだ私は次のエラーを取得します:
Exception in thread "main" java.time.format.DateTimeParseException: Text 'Wed July 2019 10:53 PM' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {DayOfWeek=3, MonthOfYear=7, Year=2019},ISO resolved to 22:53 of type java.time.format.Parsed
変更yyyy
にYYYY
とh
するhh
任意の異なる結果が得られませんでした。
よるSO上この回答やドキュメント、私のパターンは、供給されたテキストと一致しているようです。
何が私が間違っているのでしょうか?
感謝
akk202:
欠落日のヶ月
あなたの入力文字列は、月の日付を欠いています。これは、「2019年7月」ではなく何を言う日 7月内。
(あなたがフォーマッタを使用して、既存のLocalDateTimeをフォーマットすることができますが、戻ってそれを解析することができないように)フォーマットされた日付文字列は不可逆的です。それは日の値を欠けているよう。