Java Date Time Java Java API
java.time.LocalDateTime
public LocalDateTime withMonth(int month)
Returns a copy of this LocalDateTime with the month-of-year field replaced with the specified
month value. This method will throw exception for an invalid value e.g. 13.
package com.logicbig.example.localdatetime;import java.time.LocalDateTime;public class WithMonthExample { public static void main (String... args) { LocalDateTime d = LocalDateTime.of(2000, 1, 2, 10, 20, 30); LocalDateTime d2 = d.withMonth(11); System.out.println(d2); }}
2000-11-02T10:20:30