문제

How to convert Date to Timestamp in java?

This line give me the following error: "The constructor Timpestamp(Date) is undefined"

Timestamp timestamp = new Timestamp(Date);
도움이 되었습니까?

해결책

Try this:

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;
}

다른 팁

Timestamp timestamp = new Timestamp(new Date().getTime());

or

Timestamp timestamp = new Timestamp(date.getTime());

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top