VOOZH about

URL: https://www.geeksforgeeks.org/java/java-sql-timestamp-getnanos-function-with-examples/

⇱ Java SQL Timestamp getNanos() function with examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java SQL Timestamp getNanos() function with examples

Last Updated : 6 Jun, 2022

The getNanos() function is a part of Timestamp class of Java SQL.The function is used to get the fractional part of the seconds value of the Timestamp Object. The function returns the object's nanos value . Function Signature:

public int getNanos()

Syntax:

ts1.getNanos();

Parameters: The function does not accept any parameter. Return value: The function returns an integer value which is the object's nanos value Exception: The function does not throw any exception Below examples illustrate the use of getNanos() function Example 1: Create a timestamp and use the getNanos() to get the fractional part of timestamp object. 

Output:
Timestamp time : 1970-01-01 00:00:10.0
New Timestamp time : 1970-01-01 00:00:10.001
 Fractional Part :1000000

Example 2: Create a timestamp and use the getNanos() to get the fractional part of timestamp object and dont set any fractional value of seconds 

Output:
Timestamp time : 1970-01-01 00:00:10.0
Fractional Part : 0

Reference: https:// docs.oracle.com/javase/7/docs/api/java/sql/Timestamp.html

Comment