Close

Java Date Time - OffsetDateTime.adjustInto() Examples

Java Date Time Java Java API 


Class:

java.time.OffsetDateTime

java.lang.Objectjava.lang.Objectjava.time.OffsetDateTimejava.time.OffsetDateTimejava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Method:

public Temporal adjustInto(Temporal temporal)

This method adjusts the specified temporal object to have the same date, time and offset fields as this object

This method will throw UnsupportedTemporalTypeException if the provided temporal object does not support the OffsetDateTime fields.



Examples


package com.logicbig.example.offsetdatetime;

import java.time.*;
import java.time.temporal.Temporal;

public class AdjustIntoExample {

public static void main (String... args) {
OffsetDateTime d = OffsetDateTime.of(LocalDate.ofYearDay(2016, 300),
LocalTime.NOON,
ZoneOffset.ofHours(-6));
System.out.println(d);

ZonedDateTime z = ZonedDateTime.now();

System.out.println(z);

Temporal t = d.adjustInto(z);
System.out.println(t);

//alternatively
ZonedDateTime z2 = z.with(d);
System.out.println(z2);
}
}

Output

2016-10-26T12:00-06:00
2017-05-01T15:54:46.281-05:00[America/Chicago]
2016-10-26T12:00-05:00[America/Chicago]
2016-10-26T12:00-05:00[America/Chicago]




See Also