Java Timestamp from() MethodThe from() method of Timestamp class obtains an instance of Timestamp from an Instant object. SyntaxParametersThe parameter 'instant' represents the instant to convert. ReturnsThe from() method of Timestamp class returns an Timestamp which represents the same point on the time-line as that of instant. ThrowsThe 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 1Test it NowOutput: from() method will return 2018-09-02 22:05:31.689 Example 2Test it NowOutput: from() method will return 1970-01-01 05:41:18.0 Example 3Test it NowOutput: 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
|