baeldung-articles : BAEL - 6592 (#15682)
Difference between ZoneOffset.UTC and ZoneId.of("UTC")
This commit is contained in:
parent
9aa37e2746
commit
c97e529deb
|
@ -0,0 +1,25 @@
|
||||||
|
package com.baeldung.zoneoffsetandzoneidof;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
public class ZoneOffSetAndZoneIdOfUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenOffsetDateTimeWithUTCZoneOffset_thenOffsetShouldBeUTC() {
|
||||||
|
OffsetDateTime dateTimeWithOffset = OffsetDateTime.now(ZoneOffset.UTC);
|
||||||
|
assertEquals(dateTimeWithOffset.getOffset(), ZoneOffset.UTC);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenZonedDateTimeWithUTCZoneId_thenZoneShouldBeUTC() {
|
||||||
|
ZonedDateTime zonedDateTime = ZonedDateTime.now(ZoneId.of("UTC"));
|
||||||
|
assertEquals(zonedDateTime.getZone(), ZoneId.of("UTC"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue