LocalTime withNano() method in Java with Examples
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.
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:
Old LocalTime: 19:34:50.630 New LocalDateTime: 19:34:50.000100
Old LocalTime: 01:21:30.130 New LocalDateTime: 01:21:30.000999999
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.