How to convert from java.sql.Timestamp to java.util.Date?

后端 未结 8 1473
心在旅途
心在旅途 2020-12-03 02:49

i.e. this code

startDate = new Date(timestampValue.getTime));

gives me :

2012-16-02 05:16:17

相关标签:
8条回答
  • 2020-12-03 02:58
    java.sql.ResultSet rs;
    //fill rs somehow
    java.sql.Timestamp timestamp = rs.getTimestamp(1); //get first column
    long milliseconds = timestamp.getTime() + (timestamp.getNanos() / 1000000);
    java.util.Date date = return new java.util.Date(milliseconds);
    
    0 讨论(0)
  • 2020-12-03 03:15

    The fancy new Java 8 way is Date.from(timestamp.toInstant()). See my similar answer elsewhere.

    0 讨论(0)
提交回复
热议问题