Frage

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);
War es hilfreich?

Lösung

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

Andere Tipps

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

or

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top