A Java Program to convert java.time.Instant to java.sql.Timestamp 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.time.Instant to java.sql.Timestamp | |
* | |
* @author Gaurav Kukade at coderolls.com | |
* | |
*/ | |
public class InstantToTimestamp { | |
public static void main(String[] args) { | |
// get Timestamp from Instant | |
Instant instant = Instant.now(); | |
Timestamp timestamp = Timestamp.from(instant); | |
System.out.println("Instant To Timestamp: " +timestamp); // 2021-05-13 21:07:44.381 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment