There is a whole set of date's classes in Java 8:
java.time.LocalDateTime
;java.time.ZonedDateTime
;java.time.Instant
;java.time.OffsetDateTime
;java.sql.Timestamp
;java.util.Date
.
I already passed over their JavaDocs and paid attention that all these classes contain all the methods I need. Thus, for the moment, I can select them randomly. But I guess that there is some reason why there are 6 separate classes and each of them is dedicated to the specific purpose.
Technical information & requirements:
- The input is in
String
, which is converted to one of these date formats. - I don't need to display the time zones but when I compare two dates it's important to be capable to compare correctly the time in New York and in Paris.
- The precise level is seconds, there is no need to use milliseconds.
- The required operations:
- find max/min date;
- sort objects by date;
- calculate date & time period (difference between two dates);
- insert objects to MongoDB and retrieve them from a db by date (e.g. all objects after specific date).
My questions:
Which aspects should I bear in mind in order to choose the optimal format among these four options from the performance & maintainability points of view?
Is there any reason why I should avoid some of these date classes?