The other Answers are correct. A few more notes here.
java.time
Why is new java.util.Date(Long.MIN_VALUE) in Java
New? Not new at all. The java.util.Date
class is very old, bundled with the original release of Java.
That troublesome old class is now legacy, supplanted by the java.time classes. Specifically, the Instant
class. To convert to/from, see new methods added to the old class.
As for the maximum/epoch/minimum values, those are defined as constants.
Beware of using the limits
Beware of making any practical use of the minimum or maximum value.
If your intent is for something like meaning "unknown value", use another value. Many other tools such as databases will have very different limits, so you may run into problems. Also, such extreme values may not have any recognizable meaning to future readers/programmers/admins. Such values may even be mistaken for an error or bug.
If working with only recent dates, I would use the Instant.EPOCH
for such a flag. The start of 1970 is recognizable by many technical folks as being special.
ISO 8601
The strings seen above are all in standard ISO 8601 format.
The java.time classes use these standard formats by default when parsing/generating strings.
To generate strings in other formats, see the DateTimeFormatter
class.
Java 8 and later
I am using Java 8.
Then you should definitely be migrating from the old classes to modern java.time classes. They are an enormous improvement.
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.
With a JDBC driver complying with JDBC 4.2 or later, you may exchange java.time objects directly with your database. No need for strings or 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.