本文介绍了如何比较创建为JodaTime LocalDate和LocalDateTime的两个日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
LocalDate startDate = new LocalDate(2014,1,2);
LocalDateTime startDateTime = new LocalDateTime(2014,1,2,14,0);
我需要比较 startDate
和 startDateTime
关于日期,如下所示:
I need to compare startDate
and startDateTime
with respect to the date, something like this:
// boolean equalDates = startDate.isequal(startDateTime.getDate());
是否可以这样做?
推荐答案
如果您只想比较日期部分,可以这样做:
If you just want to compare the date part, you can do it like so:
LocalDate startDate = new LocalDate(2014, 1, 2);
LocalDateTime startDateTime = new LocalDateTime(2014, 1, 2, 14, 0);
LocalDate forCompare = startDateTime.toLocalDate();
System.out.println("equal dates: " + forCompare.equals(startDate));
// equal dates: true
这篇关于如何比较创建为JodaTime LocalDate和LocalDateTime的两个日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!