Java Date Time Java Java API
java.time.OffsetDateTime
public OffsetDateTime withDayOfMonth(int dayOfMonth)
Returns a copy of this OffsetDateTime with the day-of-month replaced with the provided 'dayOfMonth'
package com.logicbig.example.offsetdatetime;import java.time.OffsetDateTime;import java.time.ZoneOffset;public class WithDayOfMonthExample {public static void main(String... args) { OffsetDateTime d = OffsetDateTime.of(2014, 12, 15, 18, 29, 32, 3000000, ZoneOffset.ofHours(-5)); System.out.println(d); OffsetDateTime d2 = d.withDayOfMonth(27); System.out.println(d2);}}
2014-12-15T18:29:32.003-05:002014-12-27T18:29:32.003-05:00