我有一个准备好的声明
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 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
“Char 不能被取消引用"错误quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用错误)
Java Switch 语句 - 是“或"/“和"可能的?Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 语句 - 是“或/“和可能的?)
Java替换字符串特定位置的字符?Java Replace Character At Specific Position Of String?(Java替换字符串特定位置的字符?)
具有 int 和 char 操作数的三元表达式的类型是什么What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作数的三元表达式的类型是什么?)
读取文本文件并存储出现的每个字符Read a text file and store every single character occurrence(读取文本文件并存储出现的每个字符)
为什么我需要在 byte 和 short 上显式转换 char 原语Why do I need to explicitly cast char primitives on byte and short?(为什么我需要在 byte 和 short 上显式转换 char 原语?)