Other answers may be correct, but use obsolete classes.
java.time
Old date and time classes (java.util.Date/.Calendar, etc.) have been superseded by the java.time framework built into Java 8 and later.
The java.time classes are inspired by Joda-Time , defined by JSR 310 , extended by the ThreeTen-Extra project, ported to Java 6 and 7 by the ThreeTen-Backport project, and adapted for Android in the ThreeTenABP project. See the tutorial .
For a moment on the timeline in UTC with a nanosecond resolution, use Instant . Given the offset from UTC , use OffsetDateTime . For the time zone (offset + rules for anomalies), use ZonedDateTime , but min / max and ZoneId do not matter in ZoneId . For a date value only with no time and no time zone, use LocalDate . For a time of day with no date and no time zone, use LocalTime . For date and time without a time zone, use LocalDateTime .
All predefined constants are listed below.
Caution: be careful when using these values ββas a kind of flag or special value. Many other software libraries and databases may not support these extreme values.
For a flag or special value, such as a non-zero βno valueβ, I suggest choosing an arbitrary moment, but I avoid going to such extreme achievements both backward and forward in time. Perhaps the date of reference to the Unix era , the first moment of 1970 at UTC, 1970-01-01T00: 00: 00Z. Defined as a constant in Java: Instant.EPOCH
About java.time
The java.time framework is built into Java 8 and later. These classes supersede the nasty old obsolete time classes such as java.util.Date , Calendar and SimpleDateFormat .
The Joda-Time project, now in maintenance mode , advises switching to the java.time classes.
To learn more, check out the Oracle tutorial . And search for qaru for many examples and explanations. The specification is JSR 310 .
You can exchange java.time objects directly with your database. Use a JDBC driver compatible with JDBC 4.2 or later. No strings needed, no java.sql.* Needed.
Where can I get java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a proof of possible future additions to java.time. Here you can find useful classes such as Interval , YearWeek , YearQuarter and others .