Javatpoint Logo
Javatpoint Logo

Java Timestamp from() Method

The from() method of Timestamp class obtains an instance of Timestamp from an Instant object.

Syntax

Parameters

The parameter 'instant' represents the instant to convert.

Returns

The from() method of Timestamp class returns an Timestamp which represents the same point on the time-line as that of instant.

Throws

The from() method of Timestamp class throws :

NullPointerException- if the instance is null.

IllegalArgumentException-if the instant is too large to represent as a Timestamp

Example 1

Test it Now

Output:

from() method will return 2018-09-02 22:05:31.689

Example 2

Test it Now

Output:

from() method will return 1970-01-01 05:41:18.0

Example 3

Test it Now

Output:

Exception in thread "main" java.lang.NullPointerException
	at java.sql.Timestamp.from(Timestamp.java:598)
	at com.javaTpoint.JavaTimestampFromExample3.main(JavaTimestampFromExample3.java:8)
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