如何在java.sql.Timestamp中使用Joda-Time [英] How to use Joda-Time with java.sql.Timestamp

查看:230
本文介绍了如何在java.sql.Timestamp中使用Joda-Time的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个准备好的声明

INSERT INTO mst(time) VALUES (?);

其中时间类型为 PostgreSQL中的/current/static/datatype-datetime.html\"rel =noreferrer>时间戳 数据库。

我正在插入 Joda-Time DateTime 对象,或者我应该说我是尝试去。我找不到将DateTime对象转换为 java的方法.sql.Timestamp 的。我已经阅读了Joda-Time文档并且没有参考这个。

where time is of type Timestamp in a PostgreSQL database.
I am inserting a Joda-Time DateTime object, or I should say I am trying to. I can find no way to convert the DateTime object into a java.sql.Timestamp. I have read the Joda-Time docs and see no reference to this.

谢谢。

推荐答案

您可以先将Joda DateTime转换为long(自纪元以来的毫秒),然后再创建一个时间戳。

You can convert a Joda DateTime to a long (millis since the epoch) first, and then create a Timestamp from that.

DateTime dateTime = new DateTime();
Timestamp timeStamp = new Timestamp(dateTime.getMillis());

这篇关于如何在java.sql.Timestamp中使用Joda-Time的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆