Created
May 14, 2021 18:37
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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