Java SE API
ZoneRules.getValidOffsets()
Find valid offsets; ordinary time has one, gap zero, typical overlap two. Java SE API; example uses Java 21-compatible syntax.
Formal Syntax & Structure
java syntaxjava
List<ZoneOffset> getValidOffsets(LocalDateTime localDateTime)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| localDateTime | LocalDateTime | Local date and time |
Return Value
List<ZoneOffset>
Find valid offsets; ordinary time has one, gap zero, typical overlap two.
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-03-31T02:30"); System.out.println(zone.getRules().getValidOffsets(local).size()); System.out.println(local.atZone(zone).toLocalTime()); try { ZonedDateTime.ofStrict(local, ZoneOffset.ofHours(1), zone); } catch (DateTimeException ex) { System.out.println("invalid local time"); } }}