Converting java.sql.Date to java.util.Date

后端 未结 6 2089
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 06:07

What\'s the simplest way to convert a java.sql.Date object to a java.util.Date while retaining the timestamp?

I tried:

java.util.Date newDate = new D         


        
6条回答
  •  伪装坚强ぢ
    2020-12-05 07:10

    From reading the source code, if a java.sql.Date does actually have time information, calling getTime() will return a value that includes the time information.

    If that is not working, then the information is not in the java.sql.Date object. I expect that the JDBC drivers or the database is (in effect) zeroing the time component ... or the information wasn't there in the first place.

    I think you should be using java.sql.Timestamp and the corresponding resultset methods, and the corresponding SQL type.

提交回复
热议问题