Skip to content

Instantly share code, notes, and snippets.

@gauravkukade
Created May 14, 2021 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gauravkukade/a031b1904d4efaf758a59462ee2dc02e to your computer and use it in GitHub Desktop.
Save gauravkukade/a031b1904d4efaf758a59462ee2dc02e to your computer and use it in GitHub Desktop.
A Java Program to convert java.sql.Timestamp to java.time.Instant Check blogpost at https://coderolls.com/how-to-get-current-timestamps-in-java/
import java.sql.Timestamp;
import java.time.Instant;
/**
* A Java Program to convert java.sql.Timestamp to java.time.Instant
*
* @author Gaurav Kukade at coderolls.com
*
*/
public class TimestampToInstant {
public static void main(String[] args) {
//get instnat from the java.sql.Timestamp
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
Instant instant = timestamp.toInstant();
System.out.println("Timestamp To Instant: " +instant); // 2021-05-13T15:39:08.046Z
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment