LocalDate startDate = new LocalDate(2014,1,2); LocalDateTime startDateTime = new LocalDateTime(2014,2,14,0);
我需要比较startDate和startDateTime相关的日期,如下所示:
// boolean equalDates = startDate.isequal(startDateTime.getDate());
是否有可能做到这一点?
解决方法
如果您只想比较日期部分,可以这样做:
LocalDate startDate = new LocalDate(2014,2); LocalDateTime startDateTime = new LocalDateTime(2014,0); LocalDate forCompare = startDateTime.toLocalDate(); System.out.println("equal dates: " + forCompare.equals(startDate)); // equal dates: true