Java ZoneRules class

Description

Java ZoneRules class

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.zone.ZoneOffsetTransition;
import java.time.zone.ZoneRules;
import java.util.List;

public class Main {
  public static void main(String[] args) {
    LocalDateTime now = LocalDateTime.now();
    System.out.println("Current Date Time: " + now);

    ZoneId fixedZoneId = ZoneId.of("+06:00");
    ZoneId usChicago = ZoneId.of("America/Chicago");

    // Print some zone rules for ZoneIds
    printDetails(fixedZoneId, now);/*from w  w  w  . j  a  va2  s. c  o m*/
    printDetails(usChicago, now);
  }

  public static void printDetails(ZoneId zoneId, LocalDateTime now) {
    System.out.println("Zone ID: " + zoneId.getId());

    ZoneRules rules = zoneId.getRules();
    boolean isFixedOffset = rules.isFixedOffset();
    System.out.println("isFixedOffset(): " + isFixedOffset);
    ZoneOffset offset = rules.getOffset(now);
    System.out.println("Zone offset: " + offset);

    List<ZoneOffsetTransition> transitions = rules.getTransitions();
    System.out.println(transitions);
  }
}



PreviousNext

Related