2016-09-23 6 views
1

Java의 DateTimeFormatter에 문제가 있습니다.DateTimeFormatter 예외

나는 다음과 같은 코드가 있습니다

DateTimeFormatter format = DateTimeFormatter.ofPattern("dd/MM/yyyy"); 
LocalDateTime startDate = LocalDateTime.now(); 
LocalDateTime endDate = LocalDateTime.parse(ceremonyDetails.getDate(), format); 
System.out.println(ChronoUnit.DAYS.between(startDate, endDate)); format); 

형식의 문자열에서 현재와 날짜 사이의 일을 인쇄해야 '/ 09/2016과 같은 1929'을/MM/YYYY를 위해 dd '.

java.time.format.DateTimeParseException: Text '29/09/2016' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 2016-09-29 of type java.time.format.Parsed] with root cause java.time.DateTimeException: Unable to obtain LocalTime from TemporalAccessor: {},ISO resolved to 2016-09-29 of type java.time.format.Parsed

내가 무엇을 놓치고 :

그러나, 나는이 오류가 무엇입니까?

+0

이 날짜를 추가하는 방법을 알고 싶습니다. 코드에 있습니까? /를 이스케이프 처리해야 할 수도 있습니다. –

+0

@BertVerhees, 제 디버거에서 날짜가 정확히 '29/09/2016 '입니다. – uksz

+0

@ SkaryWombat, 방금 알아 냈습니다. 그게 문제 였어 :) – uksz

답변

3

LocalDateTime 대신 LocalDate을 사용해야합니다. 하나는 날짜 전용 값이고 다른 하나는 시각 값이있는 날짜입니다.

LocalDate.parse("29/09/2016" , DateTimeFormatter.ofPattern("dd/MM/yyyy")) 

DateTimeFormatter 클래스 설명서 페이지의 예제를 참조하십시오.

관련 문제