Java SQL Timestamp getTime() function with examples
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.
public long 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.
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
Timestamp time : 1969-12-31 23:59:50.0 Time in milliseconds : -10000
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.