Close

Java Date Time - OffsetDateTime.withOffsetSameLocal() 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 OffsetDateTime withOffsetSameLocal(ZoneOffset offset)

This method returns a copy of OffsetDateTime representing the same 'LocalDateTime' but with offset part adjusted to the provided 'offset'.



Examples


package com.logicbig.example.offsetdatetime;

import java.time.OffsetDateTime;
import java.time.ZoneOffset;

public class WithOffsetSameLocalExample {

public static void main(String... args) {
OffsetDateTime d = OffsetDateTime.of(2015, 10, 5, 15,
30, 10, 1000000, ZoneOffset.ofHours(-5));
System.out.println(d);

OffsetDateTime d2 = d.withOffsetSameLocal(ZoneOffset.of("+5"));
System.out.println(d2);
}
}

Output

2015-10-05T15:30:10.001-05:00
2015-10-05T15:30:10.001+05:00




See Also