In Java 8 there is new package introduced related to Date and Time java.time package.
This improvement is done against JSR - 310 by threeten.org
Why we need another Date/Time class in Java 8 as there is already lots of Date/Time class available in previous Java versions ?
In previous versions of JDK we didn't find good support for date/time operation. Everything thing jumbled up together in Date and Calendar class as a result it is not convenient to use for developer.
Date and Time is wrapped in Date class. So whenever we need to do operations related to date only then we need to remove the time component from Date object. To do simple things developers need to write lots of extra code just to do formatting, getting date/time and day light saving. Using Date class we cannot go below milliseconds.
More than that Date class have lots of bugs in API and equals method equality breaks when using date object case to case basis.
In case of Calendar class it better than Date but it still have some problems like date formatting support is not available. We need to covert Calendar object to Date object to do formatting.
So, what we are going to get in JDK 8 Date and Time ?
Examples can be downloaded from https://github.com/andysundar/JDK8
- Clear bug free API for date, time and date-time.
- All these objects are thread safe as these objects are immutable.
- Package are organised well and classes are design to cater API extensible.
Examples can be downloaded from https://github.com/andysundar/JDK8