The following code prints out "3920-06-02", but it's supposed to be "2020-05-02". What did I do wrong?
import java.sql.Date
// ...
public static void main(String[] args) {
Date May0220 = new Date(2020, 5, 2);
System.out.println(May0220.toString());
}
I want to use java.sql and not java.util.
LocalDate May0220 = LocalDate.of(2020, 5, 2);Date sqlDate = Date.valueOf(May0220)LocalDateworks very nicely with SQL date. Insert & fetch java.time.LocalDate objects to/from an SQL database such as H2. You don’t wantjava.sql.Date. It’s poorly designed (you haven’t seen but a slight bit of its problems) and long outdated.