Close

Java Date Time - LocalTime.withNano() Examples

Java Date Time Java Java API 


Class:

java.time.LocalTime

java.lang.Objectjava.lang.Objectjava.time.LocalTimejava.time.LocalTimejava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Method:

public LocalTime withNano(int nanoOfSecond)

Returns a copy of this LocalTime with the nano-of-seconds field replaced with the specified value.



Examples


package com.logicbig.example.localtime;

import java.time.LocalTime;

public class WithNanoExample {

public static void main (String... args) {
LocalTime t = LocalTime.of(5, 1, 5, 3000);
System.out.println(t);

LocalTime t2 = t.withNano(5000000);
System.out.println(t2);
}
}

Output

05:01:05.000003
05:01:05.005




See Also