How to use Joda-Time with java.sql.Timestamp(如何将 Joda-Time 与 java.sql.Timestamp 一起使用)
问题描述
我有一个准备好的声明
INSERT INTO mst(time) VALUES (?);
其中时间的类型是 时间戳 在 PostgreSQL 数据库.
我正在插入 Joda-Time DateTime 对象,或者我应该说我正在尝试.我找不到将 DateTime 对象转换为 java 的方法.sql.时间戳.我已阅读 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());
这篇关于如何将 Joda-Time 与 java.sql.Timestamp 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将 Joda-Time 与 java.sql.Timestamp 一起使用


基础教程推荐
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 降序排序:Java Map 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01