LocalTime withNano() method in Java with Examples Last Updated : 06 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The withNano() method of a LocalTime class is used to get a copy of this LocalTime with the nanos changed to the nanos passed as the parameter to this method. The remaining values of this LocalTime will remain the same. This instance is immutable and unaffected by this method call. Syntax: public LocalTime withNano(int nano) Parameters: This method accepts a single parameter nano which represents the nano-of-second to set in the result, from 0 to 999, 999, 999. Return value: This method returns a LocalTime instance based on this time with the requested nano. Exception: This method throws a exception DateTimeException if the nano value is invalid Below programs illustrate the withNano() method: Program 1: Java // Java program to demonstrate // LocalTime.withNano() 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"); // print time System.out.println("Old LocalTime: " + time); // Get a new LocalDateTime with nanos 100000 LocalTime newtime = time.withNano(100000); // print result System.out.println("New LocalDateTime: " + newtime); } } Output: Old LocalTime: 19:34:50.630 New LocalDateTime: 19:34:50.000100 Program 2: Java // Java program to demonstrate // LocalTime.withNano() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalTime object LocalTime time = LocalTime.parse("01:21:30.13"); // print time System.out.println("Old LocalTime: " + time); // Get a new LocalDateTime with nanos 999999 LocalTime newtime = time.withNano(999999); // print result System.out.println("New LocalDateTime: " + newtime); } } Output: Old LocalTime: 01:21:30.130 New LocalDateTime: 01:21:30.000999999 References: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#withNano(int) Comment More infoAdvertise with us Next Article LocalDateTime withNano() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-time package Java-LocalTime Practice Tags : Java Similar Reads LocalDateTime withNano() method in Java with Examples withNano() method of LocalDateTime class in Java is used to get a copy of this LocalDateTime with the nano-seconds changed to the nano-seconds passed as the parameter to this method. The remaining values of this LocalDateTime remain the same. Syntax: public LocalDateTime withNano(int nanoSeconds) Pa 3 min read LocalDateTime withNano() method in Java with Examples withNano() method of LocalDateTime class in Java is used to get a copy of this LocalDateTime with the nano-seconds changed to the nano-seconds passed as the parameter to this method. The remaining values of this LocalDateTime remain the same. Syntax: public LocalDateTime withNano(int nanoSeconds) Pa 3 min read LocalDateTime withNano() method in Java with Examples withNano() method of LocalDateTime class in Java is used to get a copy of this LocalDateTime with the nano-seconds changed to the nano-seconds passed as the parameter to this method. The remaining values of this LocalDateTime remain the same. Syntax: public LocalDateTime withNano(int nanoSeconds) Pa 3 min read LocalTime with() Method in Java with Examples In LocalTime class, there are two types of with() method depending upon the parameters passed to it. with(TemporalAdjuster adjuster) with(TemporalAdjuster adjuster) method of the LocalTime class used to adjusted this time using TemporalAdjuster and after adjustment returns the copy of adjusted time. 3 min read LocalTime withHour() method in Java with Examples The withHour() method of a LocalTime class is used to get a copy of this LocalTime with the hours changed to the hours passed as the parameter to this method. The remaining values of this LocalTime will remain the same. This instance is immutable and unaffected by this method call. Syntax: public Lo 2 min read LocalTime withSecond() method in Java with Examples The withSecond() method of a LocalTime class is used to get a copy of this LocalTime with the seconds changed to the seconds passed as the parameter to this method. The remaining values of this LocalTime will remain the same. This instance is immutable and unaffected by this method call. Syntax: pub 2 min read Like