12

My data is in format:

2010-12-01 09:59:00.423

getDate in Java only returns the date portion. Is there a way to also extract the time?

1 Answer 1

25

The SQL DATE type indeed only contains the date portion, not the time. But your column is apparently of TIMESTAMP type, so to get the full timestamp, use ResultSet#getTimestamp() instead.

Date date = resultSet.getTimestamp("columnname");
// ...

It returns java.sql.Timestamp which is a subclass of java.util.Date, so the upcast is safe.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.