Java SQL Timestamp getTime() function with examples Last Updated : 06 Mar, 2019 Comments Improve Suggest changes Like Article Like Report The getTime() function is a part of Timestamp class of Java SQL.The function is used to get the time of the Timestamp object. The function returns time in milliseconds which represents the time in milliseconds after 1st January 1970. Function Signature: public long getTime() Syntax: ts1.getTime(); Parameters: The function does not require any parameter. Return value: The function returns long value representing time in milliseconds. Exception: The function does not throw any exceptions. Below examples illustrate the use of getTime() function Example 1: Create a timestamp and use the getTime() to get the time of timestamp object. Java // Java program to demonstrate the // use of getTime() function import java.sql.*; class GFG { public static void main(String args[]) { // Create two timestamp objects Timestamp ts = new Timestamp(10000); // Display the timestamp object System.out.println("Timestamp time : " + ts.toString()); System.out.println("Time in milliseconds : " + ts.getTime()); } } Output: Timestamp time : 1970-01-01 00:00:10.0 Time in milliseconds : 10000 Example 2: Create a timestamp and use the getTime() to get the time of timestamp object and set the time before 1st January 1970. The negative long value represents the time before 1st January 1970 Java // Java program to demonstrate the // use of getTime() function import java.sql.*; public class solution { public static void main(String args[]) { // Create two timestamp objects Timestamp ts = new Timestamp(-10000); // Display the timestamp object System.out.println("Timestamp time : " + ts.toString()); System.out.println("Time in milliseconds : " + ts.getTime()); } } Output: Timestamp time : 1969-12-31 23:59:50.0 Time in milliseconds : -10000 Reference: https:// docs.oracle.com/javase/7/docs/api/java/sql/Timestamp.html Comment More infoAdvertise with us Next Article Java SQL Timestamp getTime() function with examples A andrew1234 Follow Improve Article Tags : Java Java - util package Java-Functions Java-Sql package Practice Tags : Java Similar Reads Java SQL Timestamp getNanos() function with examples The getNanos() function is a part of Timestamp class of Java SQL.The function is used to get the fractional part of the seconds value of the Timestamp Object. The function returns the object's nanos value . Function Signature: public int getNanos() Syntax: ts1.getNanos(); Parameters: The function do 2 min read Java SQL Timestamp setTime() function with examples The setTime() function is a part of Timestamp class of Java SQL.The function is used to set the time of the Timestamp object. The function takes time in milliseconds which represents the time in milliseconds after 1st January, 1970. Function Signature: public void setTime(long t) Syntax: ts1.setTime 2 min read Java SQL Timestamp before() function with examples The before() function is a part of Timestamp class of Java SQL.The function returns a boolean value representing whether the Timestamp object occurs before the given Timestamp object. Function Signature: public boolean before(Timestamp t) Syntax: ts1.before(ts2); Parameters: The function accepts Tim 2 min read Java SQL Timestamp after() function with examples The after() function is a part of Timestamp class of Java SQL.The function returns a boolean value representing whether the Timestamp object occurs after the given Timestamp object . Function Signature: public boolean after(Timestamp t) Syntax: ts1.after(ts2); Parameters: The function accepts Timest 2 min read Java SQL Timestamp setNanos() function with examples The setNanos() function is a part of Timestamp class of Java SQL.The function is used to set the fractional part of the second's value of the Timestamp Object. The function sets the object's Nanos value to the given value.Function Signature: public void setNanos(int t) Syntax: ts1.setNanos(l); Param 2 min read Like