In current development, you should prefer LocalDateTime and other Java8 time classes.
They provide the advantage of a clearer separation between point-in-time ( Instant ) and duration ( Duration ) or fragment-based definitions ( LocalDate , LocalTime ).
They allow a really good set of methods for manipulation / computation logic (unlike java.util.Date ).
Unit conversion ( Duration.toDays() ) is also included.
Last but not least, the hellish realm of Timezone ( ZonedDateTime ).
A minor flaw is the lack of support for quite a few third-party APIs, which you might want to use. But this should just be a matter of time and the conversion from the Java8 time API to Calendar / Date is not showstopper.
If you have a mature program, then replacing older Java8 date / calendar based interfaces is just a risk until you take advantage of some of the benefits mentioned above.
If you want to replace the old TimeStamp parameter TimeStamp something from the Java8 time toolkit, you can use Instant , LocalDateTime or ZonedDateTime . The difference is that the Instant value is treated as ZoneOffset.UTC when it comes to the calculation, while LocalDateTime by definition not related to the time zone.
Hint: using LocalDateTime is a pretty nice thing if something should happen in 2018-01-02 10:24:12 for the system, for example. India and systems in the USA. In almost all other cases, you can explicitly specify the time zone using Instant or ZonedDateTime .
source share