Java Timestamp valueOf() Method25 Mar 2025 | 2 min read The 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 |
Java Method The from() method of Timestamp class obtains an instance of Timestamp from an Instant object. Syntax public static Timestamp from(Instant instant) 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...
1 min read
Java Method The hashCode() method of Timestamp class returns a hash code value for this object. Syntax public int hashCode () Parameters NA Returns The hashCode() method of Timestamp class returns a hash code value for this object. Example 1 import java.sql.Timestamp; public class JavaTimestampHashCodeExample1 { public static void main(String[] args)...
1 min read
Java Method The toLocalDateTime() method of Timestamp class converts this Timespan object to a LocalDateTime which represents the same date-time value as this Timestamp. Syntax public LocalDateTime toLocalDateTime () Parameters NA Returns The toLocalDateTime () method of Timestamp class returns a LocalDateTime object which represents the same date-time value as this...
1 min read
Java Method The setNanos() method of Timestamp class sets a nanos value for the specified integer value. Syntax public void Nanos(int n) Parameters Here the parameter 'n' represents the fractional seconds component. Throws The setNanos() method of Timestamp class throws: IllegalArgumentException- if the given argument is less than 0 and greater than...
2 min read
Java Method The before() method of Timestamp class returns Boolean value true if this Timestamp object is earlier than given Timestamp object. Syntax public Boolean before(Timestamp ts) Parameters The parameter 'ts' represents the Timestamp to compare with. Returns The before() method of Timestamp class returns : Boolean value true if this Timestamp...
2 min read
Java Method The equals () method of Timestamp class returns a Boolean value true if this Timestamp object is equal to the given object or to the given Timestamp object. Syntax public Boolean equals(Timestamp ts) public Boolean equals (Object ts) Parameters The parameter 'ts' represents the Timestamp value or...
2 min read
Java Method The getTime() method of Timestamp class returns the number of milliseconds since January 1, 1970, 00:00:00 GMT . Syntax public long getTime() Parameters NA Returns The getNanos() method of Timestamp class returns the number of milliseconds since January 1, 1970, 00:00:00 GMT . Example 1 import java.sql.Timestamp; public class JavaTimestampGetTimeExample1 { ...
1 min read
Java Method The compareTo () method of Timestamp class compares this Timestamp object to the given Timestamp object or to the given date object. Syntax public int compareTo(Timestamp ts) public int compareTo(Date o) Parameters The parameter 'ts' represents the Timestamp object to be compared to this Timespan object. The parameter 'o'...
3 min read
Java Method The after() method of Java Timestamp class returns Boolean value true if this Timestamp object is later than given Timestamp object. Syntax public Boolean after(Timestamp ts) Parameters The parameter 'ts' represents the Timestamp to compare with. Returns The after() method of Timestamp class returns : Boolean value true if this...
2 min read
Java Timestamp Timestamp provides formatting and parsing operations to support JDBC escape syntax. It also adds the ability to hold the SQL TIMESTAMP fractional seconds value. Methods Methods Description after() Returns Boolean value true if this Timestamp object comes later than given Timestamp object. before() Returns Boolean value true if this Timestamp object...
3 min read
We request you to subscribe our newsletter for upcoming updates.
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