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

Output:

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

Example 2

Output:

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

Example 3

Output:

Exception in thread "main" java.lang.NullPointerException
	at java.sql.Timestamp.from(Timestamp.java:598)
	at com.javaTpoint.JavaTimestampFromExample3.main(JavaTimestampFromExample3.java:8)