Java Timestamp setNanos() MethodThe setNanos() method of Timestamp class sets a nanos value for the specified integer value. SyntaxParametersHere the parameter 'n' represents the fractional seconds component. ThrowsThe setNanos() method of Timestamp class throws: IllegalArgumentException- if the given argument is less than 0 and greater than 999999999 Example 1Output: Timestamp : 2018-09-01 09:01:15.0 Timestamp after setting nanos : 2018-09-01 09:01:15.000054647 Example 2Output: Exception in thread "main" Timestamp : 2018-09-01 09:01:15.0 java.lang.IllegalArgumentException: nanos > 999999999 or < 0 at java.sql.Timestamp.setNanos(Timestamp.java:389) at JavaTimestampSetNanosExample2.main(JavaTimestampSetNanosExample2.java:7) An runtime exception IllegalArgumentException is thrown if the given argument is less than 0 and greater than 999999999 Next TopicJava-timestamp-settime-method |
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