Created
April 14, 2020 16:17
-
-
Save saswata-dutta/cc2236c4aa78c6093e8cf82a943d32de to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class test { | |
public static void main(String[] args) { | |
// get date and time | |
// here we use java.util.Date class for comparison with java.sql.Date | |
java.util.Date javaDate = new java.util.Date(); | |
long javaTime = javaDate.getTime(); | |
System.out.println("The Java Date is:" + | |
javaDate.toString()); | |
// get SQL date in java.sql.Date format | |
java.sql.Date sqlDate = new java.sql.Date(javaTime); | |
System.out.println("The SQL DATE is: " + | |
sqlDate.toString()); | |
// get SQL time in java.sql.Time format | |
java.sql.Time sqlTime = new java.sql.Time(javaTime); | |
System.out.println("The SQL TIME is: " + | |
sqlTime.toString()); | |
// get SQL timestamp in java.sql.Timestamp format | |
java.sql.Timestamp sqlTimestamp = | |
new java.sql.Timestamp(javaTime); | |
System.out.println("The SQL TIMESTAMP is: " + | |
sqlTimestamp.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment