tl;dr
localDate.isBefore( LocalDate.now() )
java.time.LocalDate
You are using terrible date-time classes that were supplanted years ago by the modern java.time classes. Here you want LocalDate
class.
Get today's date using the JVM’s current default time zone.
LocalDate localDate = LocalDate.now() ;
Later, grab the date again, and compare.
boolean newDate = localDate.isBefore( LocalDate.now() ) ;
Or, if you think there is a possibility of the clock being messed up, check for inequality.
boolean dateDiffers = ! localDate.isEqual( LocalDate.now() ) ;
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
.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
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?
