开发者

How do I extract a Postgres timestamp field using java?

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜