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 一起使用


- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01