Java Date Time Java Java API
java.time.OffsetDateTime
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'.
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); }}
2015-10-05T15:30:10.001-05:002015-10-05T15:30:10.001+05:00