集册 Java实例教程 了解ZoneId的时间更改规则(ZoneRules)

了解ZoneId的时间更改规则(ZoneRules)

欢马劈雪     最近更新时间:2020-01-02 10:19:05

733
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
了解ZoneId的时间更改规则(ZoneRules)

import java.time.LocalDateTime;

import java.time.ZoneId;

import java.time.ZoneOffset;// 来自 时   代     Java  公  众  号 - nowjava.com

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 bdDhaka = ZoneId.of("Asia/Dhaka");

    ZoneId usChicago = ZoneId.of("America/Chicago");

    

    // Print some zone rules for ZoneIds

    printDetails(fixedZoneId, now);

    printDetails(bdDhaka, now);

    printDetails(usChicago, now);

  }

  
  /*
   from n  o  w  j  a  v  a . c o m 
  */

  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(
展开阅读全文