如何比较创建为JodaTime LocalDate和LocalDateTime的两个日期?

前端之家收集整理的这篇文章主要介绍了如何比较创建为JodaTime LocalDate和LocalDateTime的两个日期?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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

docs

原文链接:https://www.f2er.com/java/127401.html

猜你在找的Java相关文章