java date timestamp code example
Example 1: java timestamp
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
Copy
Example 2: get current date time timestamp java
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
Date date = new Date();
Timestamp timestamp2 = new Timestamp(date.getTime());
Timestamp ts = Timestamp.from(Instant.now())
Timestamp ts = Timestamp.from(ZonedDateTime.now().toInstant()));
Instant instant = ts.toInstant();
Example 3: date to timestamp java
All you need to do is change the string within the java.text.SimpleDateFormat constructor to: "MM-dd-yyyy HH:mm:ss".
Just use the appropriate letters to build the above string to match your input date.