将 java.sql.Date 转换为 java.sql.Timestamp
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34746875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 23:16:34 来源:igfitidea点击:
Convert java.sql.Date to java.sql.Timestamp
提问by dan
Is there a way to convert java.sql.Date
to java.sql.Timestamp
?
有没有办法转换java.sql.Date
为java.sql.Timestamp
?
I have the following code:
我有以下代码:
java.sql.Date = new Date();
java.sql.Timestamp timestamp = new java.sql.Timestamp(date);
But the Timestamp constructor doesn't seem to support that variable type.
但是 Timestamp 构造函数似乎不支持该变量类型。
回答by dan
You can get the constructor that takes milliseconds as argument, like:
您可以获得以毫秒为参数的构造函数,例如:
java.sql.Date date = new Date();
java.sql.Timestamp timestamp = new java.sql.Timestamp(date.getTime());