Skip to content

Instantly share code, notes, and snippets.

@gauravkukade
Created May 14, 2021 18:35
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/ea3bc951f15be0010569d306ccafa975 to your computer and use it in GitHub Desktop.
Save gauravkukade/ea3bc951f15be0010569d306ccafa975 to your computer and use it in GitHub Desktop.
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/
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