Thursday, January 29, 2026
HomeLanguagesJavaLocalTime toNanoOfDay() method in Java with Examples

LocalTime toNanoOfDay() method in Java with Examples

The toNanoOfDay() method of LocalTime class is used to return the time as nanos of day from this LocalTime.Value returned by this method lie between 0 to 24 * 60 * 60 * 1, 000, 000, 000 – 1. 

Syntax:

public long toNanoOfDay()

Parameters: This method accepts no parameters. 

Return value: This method returns a long value which is the nano of day value and is equivalent to this time. 

Below programs illustrate the toNanoOfDay() method: 

Program 1: 

Java




// Java program to demonstrate
// LocalTime.toNanoOfDay() method
 
import java.time.*;
 
public class GFG {
    public static void main(String[] args)
    {
 
        // create a LocalTime object
        LocalTime time
            = LocalTime.parse("19:34:50.63");
 
        // extract nano of day from toNanoOfDay()
        long value = time.toNanoOfDay();
 
        // print result
        System.out.println("Nano of day: "
                           + value);
    }
}


Output:

Nano of day: 70490630000000

Program 2: 

Java




// Java program to demonstrate
// LocalTime.toNanoOfDay() method
 
import java.time.*;
 
public class GFG {
    public static void main(String[] args)
    {
 
        // create a LocalTime object
        LocalTime time
            = LocalTime.parse("23:21:45.98");
 
        // extract nano of day from toNanoOfDay()
        long value = time.toNanoOfDay();
 
        // print result
        System.out.println("Nano of day: "
                           + value);
    }
}


Output:

Nano of day: 84105980000000

Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#toNanoOfDay()

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
122 POSTS0 COMMENTS
Nango Kala
6848 POSTS0 COMMENTS
Nicole Veronica
11978 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12065 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7221 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6916 POSTS0 COMMENTS