- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
It's even worse.
Date.getTime()returns the number of milliseconds since the epoch. That gets converted into aTimestampwith the same timestamp.TimestampextendsDateso itsgetTime()does the same. The entire block can be rewritten to justDate date = new Date();To get the time part of a
DateorTimestampthere are methods to get separate fields but those work half-baked as best. Using aCalendarwas the old way to go, but since Java 8 any code usingDate,TimestamporCalendarshould preferably be rewritten to use classes from thejava.timepackage.Admin
These methods I mentioned are so half-baked they've been deprecated since Java 1.1, way back in 1997.
Edit Admin
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.
Edit Admin
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.