📌  相关文章
📜  Java中的 ZoneOffsetTransitionRule createTransition() 方法与示例

📅  最后修改于: 2022-05-13 01:55:05.741000             🧑  作者: Mango

Java中的 ZoneOffsetTransitionRule createTransition() 方法与示例

Java.time.zone.ZoneOffsetTransitionRule类的createTransition()方法用于
为特定年份创建特定区域偏移过渡的对象。

句法:

public ZoneOffsetTransition createTransition(int year)

参数:此方法采用整数值 year 必须为其生成转换实例。

返回值:该方法返回特定年份的特定区域偏移过渡的对象。

下面是说明createTransition()方法的示例:

示例 1:

// Java program to demonstrate
// createTransition() method
  
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.zone.*;
  
public class GFG {
    public static void main(String[] argv)
    {
  
        // creating and initializing
        // ZoneOffsetTransitionRule Object
        ZoneOffsetTransitionRule zonetrans1
            = ZoneOffsetTransitionRule
                  .of(
                      Month.JANUARY, 12,
                      DayOfWeek.SUNDAY,
                      LocalTime.of(03, 24, 45),
                      false,
                      ZoneOffsetTransitionRule
                          .TimeDefinition
                          .STANDARD,
                      ZoneOffset.ofTotalSeconds(8),
                      ZoneOffset.ofTotalSeconds(10),
                      ZoneOffset.ofTotalSeconds(12));
  
        // getting object of ZoneOffsetTransition
        // by using createTransition() method
        ZoneOffsetTransition zoo
            = zonetrans1.createTransition(10);
  
        // display the result
        System.out.println("ZoneOffsetTransition : "
                           + zoo);
    }
}
输出:

示例 2:

// Java program to demonstrate
// createTransition() method
  
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.zone.*;
  
public class GFG {
    public static void main(String[] argv)
    {
  
        // creating and initializing
        // ZoneOffsetTransitionRule Object
        ZoneOffsetTransitionRule zonetrans1
            = ZoneOffsetTransitionRule
                  .of(
                      Month.JANUARY, 12,
                      DayOfWeek.SUNDAY,
                      LocalTime.of(03, 24, 45),
                      false,
                      ZoneOffsetTransitionRule
                          .TimeDefinition
                          .STANDARD,
                      ZoneOffset.ofTotalSeconds(8),
                      ZoneOffset.ofTotalSeconds(10),
                      ZoneOffset.ofTotalSeconds(12));
  
        // getting object of ZoneOffsetTransition
        // by using createTransition() method
        ZoneOffsetTransition zoo
            = zonetrans1.createTransition(14);
  
        // display the result
        System.out.println(
            "ZoneOffsetTransition : "
            + zoo);
    }
}
输出:

参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/zone/ZoneOffsetTransitionRule.html#createTransition-int-