I would like to create a java.sql.Date for December 31, 9999 (UTC). Currently I'm using this:
Date eot = new Date(new GregorianCalendar(9999, Calendar.DECEMBER, 31).getTimeInMillis());
However, it strikes me as ugly. Is there a simpler way?
Why not just use a constant?
Date eot = new Date(253402214400000L);
Also note, the docs say that 8099-12-31 is the latest date supported. That would be 193444070400000L. Though in testing, it seems to work with 9999-12-31 just fine.
Also, I'll just point out you should probably avoid this API and use the java.time APIs instead.
Use Java's new LocalDate class. If you must have a java.sql.Date, you can convert it with valueOf():
Date eot = Date.valueOf(LocalDate.of(9999, Month.DECEMBER, 31));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With