-3
주세요! 이 간단한 LocalDate 구문 분석이 작동하지 않는 이유를 알고 싶습니다.LocalDate.parse (Not Working)
내 DateFormatter는 (두 가지 방식 모두에서) 작동하지만 새로운 LocalDate 변수 (동일한 Formatter 사용)를 구문 분석하려고 할 때 작동하지 않고 다음과 같은 예외가 발생합니다.
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MMM-dd-yyyy");
LocalDate date = LocalDate.now();
String dateFormatted = date.format(dateTimeFormatter);
System.out.println("Data formatted > " + dateFormatted);
String dateFormatted1 = dateTimeFormatter.format(date);
System.out.println("Data formatted 2> " + dateFormatted1);
LocalDate dateParsed = LocalDate.parse(dateTimeFormatter.format(date));
System.out.println("Data parsed > " + dateParsed);
LocalDate dateParsed2 = LocalDate.parse(dateFormatted, dateTimeFormatter);
System.out.println("Data parsed 2 > " + dateParsed2);
/////////////////////// 예외 //////////////// 당신이 포맷터없이 구문 분석 할 때, LOCALDATE이로 이해
LocalDate dateParsed = LocalDate.parse(dateTimeFormatter.format(date), dateTimeFormatter);
: //////////////
Caused by: java.time.format.DateTimeParseException: Text 'dez-11-2017' could not be parsed at index 0
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
at java.time.LocalDate.parse(LocalDate.java:400)
at java.time.LocalDate.parse(LocalDate.java:385)
at hypercaos.AddController.initialize(AddController.java:74)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)*
감사합니다. 그것은 효과가 있었다. 사실, 나는 실수를했다. 그 일을 생각하면, 변수 dateParsed를 MMM-dd-yyyy 형식으로 이미 캡처 할 수 있습니다 (나중에 LocalDate -> 문자열 형식 변환을하지 않고 표시). 하지만 그것은 yyyy-MM-dd로 다시 돌아가는 것입니다. 감사합니다. Ps .: 바보 같은 질문에 대해 죄송합니다. :-) –