Instant getNano() method in Java with Examples
The getNano() method of Instant class is used to return the number of nanoseconds later in the time-line represented in this instant, from the start of the second. The nanosecond-of-second value which measures the total number of nanoseconds from the second value returned by getEpochSecond().
Syntax:
public int getNano()
Returns: This method returns the nanoseconds within the second value which is always positive and never exceeds 999, 999, 999.
Below programs illustrate the getNano() method:
Program 1:
// Java program to demonstrate // Instant.getNano() method import java.time.*; public class GFG { public static void main(String[] args) { // create a Instant object Instant instant = Instant.parse("2018-12-30T19:34:50.63Z"); // get nano second of second secondvalue // using getNano() int value = instant.getNano(); // print result System.out.println("nanoseconds value: " + value); } } |
nanoseconds value: 630000000
Program 2:
// Java program to demonstrate // Instant.getNano() method import java.time.*; public class GFG { public static void main(String[] args) { // create a Instant object Instant instant = Instant.now(); // current Instant System.out.println("Current Instant:" + instant); // get nano second of second secondvalue // using getNano() int value = instant.getNano(); // print result System.out.println("nanoseconds value: " + value); } } |
Current Instant:2018-11-27T04:21:27.029Z nanoseconds value: 29000000
References: https://docs.oracle.com/javase/10/docs/api/java/time/Instant.html#getNano()
Recommended Posts:
- LocalDateTime getNano() method in Java with Examples
- OffsetTime getNano() method in Java with examples
- Duration getNano() method in Java with Examples
- LocalTime getNano() method in Java with Examples
- ZonedDateTime getNano() method in Java with Examples
- OffsetDateTime getNano() method in Java with examples
- Instant now() Method in Java with Examples
- Instant with() Method in Java with Examples
- Instant get() method in Java with Examples
- Instant plus() method in Java with Examples
- Instant until() Method in Java with Examples
- Instant from() method in Java with Examples
- Instant plusSeconds() method in Java with Examples
- Instant isBefore() method in Java with Examples
- Instant ofEpochSecond() Method 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 contribute@geeksforgeeks.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.



