How to convert Date to Timestamp in Java

We can convert Date to Timestamp in java using constructor of java.sql.Timestamp class.

Approach

Java



import java.sql.Timestamp;
import java.util.Date;

public class DateToTimestamp {
    public static void main(String[] args) {
        Date d = new Date();
        Timestamp ts = new Timestamp(d.getTime());
        System.out.println("Time stamp value " + d.getTime());
        System.out.println(ts);
    }
}


No comments:

Post a Comment