The setNanos() function is a part of Timestamp class of Java SQL.The function is used to set the fractional part of the second’s value of the Timestamp Object. The function sets the object’s Nanos value to the given value.
public void setNanos(int t)
Parameters: The function accepts int value t as parameter which is the nanoseconds value to be set.
Return value: The function does not return any value.
Exception: The function throws IllegalArgumentException if the parameter passed is less than 0 or greater than 999999999
Below examples illustrate the use of setNanos() function
Example 1: Create a timestamp and use the setNanos() to set the fractional part of timestamp object.
Timestamp time : 1970-01-01 00:00:10.0 New Timestamp time : 1970-01-01 00:00:10.001
Example 2: Create a timestamp and use the setNanos() to set the fractional part of timestamp object and pass negetive int value as parameter.
Timestamp time : 1970-01-01 00:00:10.0 nanos > 999999999 or < 0
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Java SQL Timestamp setTime() function with examples
- Java SQL Timestamp before() function with examples
- Java SQL Timestamp after() function with examples
- Java SQL Timestamp getTime() function with examples
- Java SQL Timestamp getNanos() function with examples
- UUID timestamp() Method in Java with Examples
- Java Program to Convert Date to TimeStamp
- Java Program to Convert TimeStamp to Date
- Performing Database Operations in Java | SQL CREATE, INSERT, UPDATE, DELETE and SELECT
- How to implement SQL GROUP BY in Java?
- Java.util.function.BiPredicate interface in Java with Examples
- Java.util.function.DoublePredicate interface in Java with Examples
- Java.util.function.LongPredicate interface in Java with Examples
- Java.util.function.IntPredicate interface in Java with Examples
- How to Execute Multiple SQL Commands on a Database Simultaneously in JDBC?
- Java.util.BitSet class methods in Java with Examples | Set 2
- Java.util.BitSet class in Java with Examples | Set 1
- Java.util.Collections.rotate() Method in Java with Examples
- Java.util.Collections.frequency() in Java with Examples
- Java.util.Arrays.equals() in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.