java.time
If you stored the date as text, parse as LocalDate
.
LocalDate localDate = LocalDate.parse( input ) ;
If you more properly stored the date in a column of a type akin to the SQL-standard DATE
type, retrieve as a LocalDate
.
LocalDate localDate = myResultSet.getObject( … , LocalDate.class ) ;
Capture the current date as seen in the wall-clock time used by the people of some particular region (a time zone).
ZoneId z = ZoneId.of( "America/Montreal" ) ;
LocalDate today = LocalDate.now( z ) ;
Calculate leaped time in days.
long days = ChronoUnit.DAYS.between( localDate , today ) ;

Tip: To represent a date range, a pair of LocalDate
objects, add the ThreeTen-Extra library to your project. Use the LocalDateRange
class.
LocalDateRange range = LocalDateRange.of( localDate , today ) ;
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?
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.