Close

Java Date Time - ZonedDateTime.withMonth() Examples

Java Date Time Java Java API 


Class:

java.time.ZonedDateTime

java.lang.Objectjava.lang.Objectjava.time.ZonedDateTimejava.time.ZonedDateTimejava.time.temporal.TemporalTemporaljava.time.chrono.ChronoZonedDateTimeChronoZonedDateTimejava.io.SerializableSerializableLogicBig

Method:

public ZonedDateTime withMonth(int month)

Returns a copy of this ZonedDateTime with month-of-year replaced with the provided 'month'

Examples


The returned time zones are different between of daylight saving changes.

package com.logicbig.example.zoneddatetime;

import java.time.ZonedDateTime;

public class WithMonthExample {

public static void main(String... args) {
ZonedDateTime d = ZonedDateTime.now();
System.out.println(d);

ZonedDateTime d2 = d.withMonth(1);
System.out.println(d2);

ZonedDateTime d3 = d.withMonth(12);
System.out.println(d3);
}
}

Output

2017-05-01T16:00:07.467-05:00[America/Chicago]
2017-01-01T16:00:07.467-06:00[America/Chicago]
2017-12-01T16:00:07.467-06:00[America/Chicago]




See Also