开发者

How do I extract a Postgres timestamp field using java?

开发者 https://www.devze.com 2023-03-09 15:30 出处:网络
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 po

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

精彩评论

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

关注公众号