Javatpoint Logo
Javatpoint Logo

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

Test it Now

Output:

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

Example 2

Test it Now

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)
Next TopicJava Timestamp





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA