如何在Java中将日期转换为时间戳?
这一行给出了以下错误: "构造函数Timpestamp(Date)未定义"
Timestamp timestamp = new Timestamp(Date);
答案 0 :(得分:1)
试试这个:
import java.util.Date;
import java.sql.Timestamp;
public Timestamp convertDateToTimestamp(Date date) {
Timestamp timestamp = null;
if (date != null) {
timestamp = new Timestamp(date.getTime());
}
return timestamp;
}
答案 1 :(得分:1)
Timestamp timestamp = new Timestamp(new Date().getTime());
或
Timestamp timestamp = new Timestamp(date.getTime());