• Rob (unregistered)

    It's even worse. Date.getTime() returns the number of milliseconds since the epoch. That gets converted into a Timestamp with the same timestamp. Timestamp extends Date so its getTime() does the same. The entire block can be rewritten to just Date date = new Date();

    To get the time part of a Date or Timestamp there are methods to get separate fields but those work half-baked as best. Using a Calendar was the old way to go, but since Java 8 any code using Date, Timestamp or Calendar should preferably be rewritten to use classes from the java.time package.

  • Rob (unregistered)

    These methods I mentioned are so half-baked they've been deprecated since Java 1.1, way back in 1997.

  • (nodebb) in reply to Rob

    It's even more worse. The Timestamp class is in java.sql package and therefore meant to be used for accessing SQL databases via JDBC. It's not a general purpose class.

    And it adds a nanosecond value to it, which doesn't make any sense here.

  • (nodebb)

    I feel every release of Java has something reinvented that doesn't need reinventing. The time and date libraries are no exception. I sympathize with the original coder.

Leave a comment on “The Date and Time and Time”

Log In or post as a guest

Replying to comment #705070:

« Return to Article