如何从java.sql.Timestamp转换为java.util.Date?

2022-08-31 20:29:13

此代码

startDate = new Date(timestampValue.getTime));

给我 :

2012-16-02 05:16:17

什么时候

System.out.println(timestampValue);

返回:

2012-01-02 05:16:17.0


答案 1

类从 扩展自 。java.sql.TimeStampjava.util.Date

您可以直接指定要引用的对象:TimeStampDate

TimeStamp timeStamp = //whatever value you have;
Date startDate = timestampValue;

答案 2

您应该改用日历

Calendar start = Calendar.getInstance();
start.setTimeInMillis( timeStampValue.getTime() );