将java.sql.Date转换为java.util.Date [英] Converting java.sql.Date to java.util.Date
本文介绍了将java.sql.Date转换为java.util.Date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在保留时间戳的同时将java.sql.Date对象转换为java.util.Date的最简单方法是什么?
What's the simplest way to convert a java.sql.Date object to a java.util.Date while retaining the timestamp?
我试过:
java.util.Date newDate = new Date(result.getDate("VALUEDATE").getTime());
没有运气。它仍然只将日期部分存储到变量中。
with no luck. It's still only storing the date portion into the variable.
推荐答案
java.sql.Date类只用于携带日期没有时间,所以你看到的转换结果对于这种类型是正确的。您需要使用java.sql.Timestamp来获取时间的完整日期。
The class java.sql.Date is designed to carry only a date without time, so the conversion result you see is correct for this type. You need to use a java.sql.Timestamp to get a full date with time.
java.util.Date newDate = result.getTimestamp("VALUEDATE");
这篇关于将java.sql.Date转换为java.util.Date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文