K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
K. Tsang wrote:The ".0" is the nanosecond in the timestamp.
java.sql.Timestamp has its own equals() method. In fact 2 equals() = equals(Object) and equals(Timestamp)
If you retrieved the timestamp using ResultSet#getTimestamp then use the equals(Timestamp) .... it should work.
Oh when you print the timestamp to console, the Timestamp class is using its toString() method which by default has that nanosecond thing. To avoid it, use the the Timestamp.valueOf(String) static method.
Hope this helps.
Dave Tolls wrote:How are you reading this out?
The Timestamp class is simply a long.
Mike London wrote:but I'm fine with using .contains() instead of .equals() since it works fine and would not cause a logical error.
Bear Bibeault wrote:
Mike London wrote:but I'm fine with using .contains() instead of .equals() since it works fine and would not cause a logical error.
I would not be. Not by a long shot. It's a hack of a major nature. I'd strongly advise doing this the right way rather than relying on a hack that just happens to work.
K. Tsang wrote:The ".0" is the nanosecond in the timestamp.
java.sql.Timestamp has its own equals() method. In fact 2 equals() = equals(Object) and equals(Timestamp)
If you retrieved the timestamp using ResultSet#getTimestamp then use the equals(Timestamp) .... it should work.
Oh when you print the timestamp to console, the Timestamp class is using its toString() method which by default has that nanosecond thing. To avoid it, use the the Timestamp.valueOf(String) static method.
Hope this helps.
Bear Bibeault wrote:No. Why are you converting to strings in the first place? Times in Java are long values, not strings.
Why are you resistant to using the API provided for java.sql.Timestamp, and just putting a lot of other stuff in the way?
Bear Bibeault wrote:But you still haven't answered the question: why not simply use the equals() method as intended?
Mike London wrote:
Then, it too had the ".0" at the end and the comparisons, using .equals(), not "contains()", worked fine.
- mike
Dave Tolls wrote:
Mike London wrote:
Then, it too had the ".0" at the end and the comparisons, using .equals(), not "contains()", worked fine.
- mike
This bit still sounds like you are comparing Strings.
What Bear is asking is why aren't you simply comparing the Timestamps?
With that structure there is no "it too had the ".0"" as that would be meaningless.
K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
K. Tsang wrote:Hi Mike,
You probably found out that valueOf(String) approach didn't work. Because the String input has an extra ".0" to begin with.
Just thinking you can also use the Timestamp#getTime() method to get the long for comparison.