3

We use new Date(), Calendar().getInstance() or LocalDateTime.now() to represent the clock now. What's the difference between LocalDateTime, Date and Calendar and why do we prefer LocalDateTime instead of the rest?

4
  • 2
    Use the newer classes, they're much more useful and better designed. If you're seeing a difference, please post a minimal reproducible example. Commented Dec 6, 2018 at 2:09
  • Because the original Date and Calendar classes leave much to be desired. Which led to Joda-Time, and eventually java.time Commented Dec 6, 2018 at 2:10
  • There are only a few instances where Date is more useful than Instant, mostly related to historical dates. Commented Dec 6, 2018 at 3:28
  • FYI, the terribly troublesome old date-time classes such as java.util.Date, java.util.Calendar, and java.text.SimpleDateFormat are now legacy, supplanted by the java.time classes built into Java 8 and later. See Tutorial by Oracle. Commented Dec 6, 2018 at 5:49

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.