Java Date Time Java Java API
java.time.LocalDateTime
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.
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); }}
2000-05-31T20:10