Close

Java Date Time - LocalDateTime.withNano() Examples

Java Date Time Java Java API 


Class:

java.time.LocalDateTime

java.lang.Objectjava.lang.Objectjava.time.LocalDateTimejava.time.LocalDateTimejava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.time.chrono.ChronoLocalDateTimeChronoLocalDateTimejava.io.SerializableSerializableLogicBig

Method:

public LocalDateTime withNano(int nanoOfSecond)

Returns a copy of this LocalDateTime with the nano-of-seconds field replaced with the specified nanoOfSecond value. This method will throw exception for an invalid value.



Examples


package com.logicbig.example.localdatetime;

import java.time.LocalDateTime;

public class WithNanoExample {

public static void main (String... args) {
LocalDateTime d = LocalDateTime.of(2000, 1, 2,
10, 20, 30, 2000);
System.out.println(d);

LocalDateTime d2 = d.withNano(10000);
System.out.println(d2);
}
}

Output

2000-01-02T10:20:30.000002
2000-01-02T10:20:30.000010




See Also