org.threeten.extra.LocalDateRange::equals
See the ThreeTen-Extra project for the LocalDateRange
class with its equals
method. This method compares one LocalDateRange
with another ensuring that the pair of dates are the same.
That class depends on the java.time.LocalDate
class built into Java 8 and later. That class has been covered many hundreds of times on this site. So search Stack Overflow for further info.
LocalDateRange.of(
LocalDate.of( 2017 , Month.JANUARY , 25 ) ,
LocalDate.of( 2017 , Month.FEBRUARY , 26 ) // Returns a `LocalDate` object.
) // Returns a `LocalDateRange` object.
.equals(
LocalDateRange.of(
LocalDate.of( 2017 , Month.MARCH , 25 ) ,
LocalDate.of( 2017 , Month.APRIL , 26 )
)
)
false
ChronoUnit.DAYS::between
If you meant to compare the number of days elapsed, use ChronoUnit
enum.
ChronoUnit.DAYS.between(
LocalDate.of( 2017 , Month.JANUARY , 25 ) ,
LocalDate.of( 2017 , Month.FEBRUARY , 26 )
) // Returns a `long` integer primitive.
==
ChronoUnit.DAYS.between(
LocalDate.of( 2017 , Month.MARCH , 25 ) ,
LocalDate.of( 2017 , Month.APRIL , 26 )
)
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
You may exchange java.time objects directly with your database. Use a JDBC driver compliant with JDBC 4.2 or later. No need for strings, no need for java.sql.*
classes.
Where to obtain the java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.