baeldung-articles : BAEL - 6592 (#15682)

Difference between ZoneOffset.UTC and ZoneId.of("UTC")
This commit is contained in:
DiegoMarti2 2024-01-18 22:26:30 +02:00 committed by GitHub
parent 9aa37e2746
commit c97e529deb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 25 additions and 0 deletions

View File

@ -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"));
}
}