Close

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

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

dayOfMonth value. This method will throw exception for a value like 32, because 32 is not a valid day of any month.



Examples


package com.logicbig.example.localdatetime;

import java.time.LocalDateTime;

public class WithDayOfMonthExample {

public static void main (String... args) {
LocalDateTime dt = LocalDateTime.of(2000, 5, 3,
20, 10);
LocalDateTime dt2 = dt.withDayOfMonth(31);
System.out.println(dt2);
}
}

Output

2000-05-31T20:10




See Also