Close

Java Date Time - LocalDateTime.withHour() 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 withHour(int hour)

Returns a copy of this LocalDateTime with the hour-of-day field replaced with the specified

hour value. This method will throw exception for an invalid value e.g. 24.



Examples


package com.logicbig.example.localdatetime;

import java.time.LocalDateTime;

public class WithHourExample {

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

Output

2000-01-02T20:20




See Also