Java Timestamp getTime() Method

The getTime() method of Timestamp class returns the number of milliseconds since January 1, 1970, 00:00:00 GMT .

Syntax

Parameters

NA

Returns

The getNanos() method of Timestamp class returns the number of milliseconds since January 1, 1970, 00:00:00 GMT .

Example 1

Output:

Timestamp : 2018-09-01 09:01:15.0
Milliseconds : 1535772675000

Example 2

Output:

Exception in thread "main" java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
	at java.sql.Timestamp.valueOf(Timestamp.java:204)
	at JavaTimestampGetTimeExample2.main(JavaTimestampGetTimeExample2.java:5)