Java Timestamp valueOf() MethodThe valueOf() method of Timestamp class converts the string object to Timestamp value or obtains an instance of Timestamp from a LocalDateTime object. SyntaxParametersHere parameter 's' and 'dateTime' represent a string value in date-time format and a LocalDateTime value . ReturnsThe valueOf() method of Timestamp class returns a Timestamp value. ThrowsThe valueOf () method of Timestamp class throws: IllegalArgumentException- if the given string argument is not in date-time(yyyy-mm-dd hh:mm:ss) format. NullPointerException- if datetime is null. Example 1Output: String : 2018-09-01 09:01:15 value of Timestamp : 2018-09-01 09:01:15.0 Example 2Output: String : 2018-09-01 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 JavaTimestampValueOfExample2.main(JavaTimestampValueOfExample2.java:7) Example 3Output: Exception in thread "main" java.lang.NullPointerException at java.sql.Timestamp.valueOf(Timestamp.java:551) at JavaTimestampValueOfExample3.main(JavaTimestampValueOfExample3.java:8) Example 4Output: value of Timestamp : 2018-09-06T12:04:44.386 Next TopicJava-spliterator |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India