Java Date
Java Util Date
The Date class is available in java.util package. It represents a specific instant in time with millisecond precision since the 1st of January 1970 00:00:00 GMT (the epoch time). In java applications, this class is used to keep coordinated universal time (UTC).
java.util.Date Example
Java SQL Date
The java.sql.date extends java.util.Date class. The main purpose is to represent SQL Date which keeps years, months and days. No time data is kept.
In fact, the date is stored as milliseconds since the 1st of January 1970 00:00:00 GMT and the time part is normalized (set to zero). Java.sql.Date should be used only when dealing with databases. The java.sql.Date instance is widely used in the JDBC because it represents the date that can be stored in a database.
java.sql.Date Example: get current date
Drawbacks of existing Date/Time API’s
Thread safety: The existing classes such as Date and Calendar does not provide thread safety. Hence it leads to hard-to-debug concurrency issues that are needed to be taken care by developers. The new Date and Time APIs of Java 8 provide thread safety and are immutable, hence avoiding the concurrency issue from developers.
Bad API designing: The classic Date and Calendar APIs does not provide methods to perform basic day-to-day functionalities. The Date and Time classes introduced in Java 8 are ISO-centric and provides number of different methods for performing operations regarding date, time, duration and periods.
Difficult time zone handling: To handle the time-zone using classic Date and Calendar classes is difficult because the developers were supposed to write the logic for it. With the new APIs, the time-zone handling can be easily done with Local and ZonedDate/Time APIs.
Java Date and Time
Until 1.7 to handle date and time values we have several classes are there like Java.util.Date , Java.util.Calander, Java.util.TimeStamp etc.
Get Karnan Sooriyakumar’s stories in your inbox
Join Medium for free to get updates from this writer.
But these classes are not that much convenient to use with respective performance and with respective convenience also. Most of the methods of these classes are deprecated and these classes are not recommended to use.
To handle date and time values very effectively, java people introduced new API that is Date and Time API in the java version 1.8. These API define several classes and interfaces to handle date and time very effectively. These API called as joda time API. This API developed by joda.org.
The core classes in the java.time package use the calendar system defined in ISO-8601 (based on the Gregorian calendar system) as the default calendar. Other non-ISO calendar systems can be represented using the java.time.chrono package and several predefined chronologies, such as Hijrah and Thai Buddhist are provided.
API Specification
java.time — Classes for date, time, date and time combined, time zones, instants, duration, and clocks.
java.time.chrono — API for representing calendar systems other than ISO-8601. Several predefined chronologies are provided and you can also define your own chronology.
java.time.format — Classes for formatting and parsing dates and time.
java.time.temporal — Extended API, primarily for framework and library writers, allowing interoperations between the date and time classes, querying, and adjustment. Fields and units are defined in this package.
java.time.zone — Classes that support time zones, offsets from time zones, and time zone rules.
Java LocalDate & LocalTime Example






