TL; DR
Instant.EPOCH
Using java.time
The inconvenient old time classes, including Date and Calendar , are now deprecated, replaced by java.time classes. Most of the java.time functions are ported to Android (see below).
To get the Java and Unix epoch link date values ββin 1970-01-01 , use LocalDate . The LocalDate class represents a date value only without time and without a time zone.
LocalDate epoch = LocalDate.ofEpochDay( 0L ) ;
epoch.toString: 1970-01-01
To get the date and time of the same era, use the Instant.EPOCH constant. The Instant class represents a moment on the UTC timeline with a nanosecond resolution (up to nine (9) decimal digits).
Instant epoch = Instant.EPOCH ;
epoch.toString (): 1970-01-01T00: 00: 00Z
Z in this ISO 8601 standard, the output does not comply with Zulu and means UTC .
To get several years, months, days since then, use the Period class.
Period period = Period.between( LocalDate.ofEpochDay( 0 ) , LocalDate.now( ZoneId.of( "America/Montreal" ) ) ) ;
Search for further discussion and examples of Period .
About java.time
The java.time framework is built into Java 8 and later. These classes supersede the nasty old legacy time classes such as java.util.Date , Calendar and SimpleDateFormat .
The Joda-Time project, now in maintenance mode , we recommend switching to the java.time classes.
To learn more, see the Oracle Tutorial . And search for qaru for many examples and explanations. JSR 310 specification .
Where to get java.time classes?
- Java SE 8 and SE 9 and later
- Built in.
- Part of the standard Java API with integrated implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and SE 7
- Android