Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 2
    If you are using Java or higher you should not use Date. That class is poorly designed and long outdated. Depending on exact requirements use Instant or another class from java.time, the modern Java date and time API. Even on Java 6 or 7 you may consider the same using ThreeTen Backport.
    – Anonymous
    Commented Dec 19, 2019 at 19:21
  • 1
    * using Java 8 or higher
    – Anonymous
    Commented Dec 21, 2019 at 14:21
  • @OleV.V. I prefer to use Date in most cases, because there is no issues to use it in DTO with Spring MVC (spring.jackson.serialization.write-dates-as-timestamps=true), no timezone problems between JavaScript (Angular, React, etc) and Java using REST. In JS just use new Date(timeFromServer) without any parsers. You don't ever think about a timezone when Date comes from frontend and goes with Hibernate (also Date) to database and vice versa. Also it perfectly works with Swagger (OpenAPI). It's very well supported by all new and old frameworks. New time API is perfect for time math.
    – pavelety
    Commented Apr 5, 2021 at 7:51
  • Date has caused innumerable time zone errors over the years. Hibernate 5 supports java.time just fine. jackson-modules-java8 too. Tastes differ.
    – Anonymous
    Commented Apr 5, 2021 at 10:02
  • Java 8+ oneliner. Nit-picking, it needs to be wrapped in a varargs method as you show in order to fill the three values into an array. So I would not call it a one-liner.
    – Anonymous
    Commented Jun 5 at 7:16