从数据库中取时间值,遇到:java.sql.Timestamp cannot be cast to java.lang.Long

将 java.sql.Timestamp 类型转换为 java.util.Date 类型。
二者其实是父子关系,直接 Date d = (Date)时间戳 就可以了。

Date d = (Date)时间戳
1
或者用以下的方法。

public static java.util.Date timeToDate(java.sql.Timestamp time) {
return time;
}

1
2
3
4
其他转换见链接
时间戳转换字符串、date

原文地址:https://www.cnblogs.com/muhy/p/12574226.html