Your code seems to be using the new java.time package in Java 8. To be sure, look at the import
statements.
The LocalDate class uses static factory methods to create instances rather than constructors. See the doc for several methods.
LocalDate now = LocalDate.now ( ZoneId.of( "America/Montreal" ) );
Or…
LocalDate localDate = LocalDate.of( 2014, 1, 23 ); // year, month, day.
If the user is entering text, parse as numbers.
LocalDate localDate = LocalDate.of( Integer.parseInt( "2014") , Integer.parseInt( "1") , Integer.parseInt( "23") );
Or parse as one string in standard ISO 8601 format.
LocalDate localDate = LocalDate.parse( "2014-01-23" ) ;
For other formats, search Stack Overflow for many discussions and examples of parsing strings with DateTimeFormatter
class.
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.
Using a JDBC driver compliant with JDBC 4.2 or later, you may exchange java.time objects directly with your database. No need for strings nor 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.