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.

Required fields*

5
  • 1
    You are ignoring the crucial need for a time zone. I do not recommend doing it this way. Also the Timestamp class is long outdated and filled with design problems, so I’d rather avoid it, especially when we can use the classes from java.time like LocalDateTime. Commented Jun 29, 2018 at 11:10
  • @OleV.V. Just curious about the design problems of Timestamp, Can you share some article on that? It helps me to avoid using Timestamp from my code as well. Thanks! Commented Jul 2, 2018 at 2:55
  • 2
    Just short, it’s implemented as a subclass of Date but often cannot be handled as a Date. Most of the methods inherited from Date and one constructor are deprecated. Its toString method uses the JVM’s time zone, which confuses many since the same Timestamp is printed differently on different computers (example). Commented Jul 2, 2018 at 3:36
  • This is perfect for unit testing. Just replace the now with LocalDate.of(year, month, day) Commented Jul 17, 2019 at 10:05
  • This should be the accepted answer to workaround the "always UTC" values. Commented Dec 25, 2019 at 2:34