Still using java.util.Date? Don’t!
Java 8 was released 3 years ago (March 2014) and brought a lot of language improvements. One of those is new Date and Time API for Java, also known as JSR-310. It represents a very rich API for working with dates and times. Yet, I see many developers still using good old java.util.Date
and java.util.Calendar
classes in the code they write today.
Sure, we still have to interact with legacy applications and old APIs, using mentioned classes. But this does not mean we can not use new java.time
API when writing new code or refactoring the old one. Why we would like to do so? Well, using the new API is simpler, more straightforward, flexible, easier to understand, classes are immutable and hence thread safe… just to mention a few.