Java SE API

ZonedDateTime.ofStrict()

Validate the local time and chosen offset against zone rules. Java SE API; example uses Java 21-compatible syntax.

Formal Syntax & Structure

java syntaxjava
static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)

Parameters & Attributes

NameTypeDescription
localDateTimeLocalDateTimeLocal date and time
offsetZoneOffsetChosen valid offset
zoneZoneIdRegion or offset zone

Return Value

ZonedDateTime

Validate the local time and chosen offset against zone rules.

Working Example

Example Snippetjava
import java.math.*;import java.time.*;import java.time.format.*;import java.time.temporal.*;import java.text.*;import java.util.*;public class Main {    public static void main(String[] args) throws Exception {        ZoneId zone = ZoneId.of("Europe/Stockholm");        LocalDateTime local = LocalDateTime.parse("2024-10-27T02:30");        var offsets = zone.getRules().getValidOffsets(local);        System.out.println(offsets.size());        var earlier = ZonedDateTime.ofStrict(local, offsets.get(0), zone);        var later = earlier.withLaterOffsetAtOverlap();        System.out.println(earlier.toInstant());        System.out.println(later.toInstant());    }}
Java Reference