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

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

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

Java.time.zone.ZoneOffsetTransitionRule类的getTimeDefinition()方法用于获取发生转换的 ZoneOffsetTransitionRule.TimeDefinition 对象的枚举值。

句法:

public ZoneOffsetTransitionRule.TimeDefinition getTimeDefinition()

参数:此方法不接受任何参数。

返回值:此方法返回发生转换的 ZoneOffsetTransitionRule.TimeDefinition 对象的枚举值。

以下是说明getTimeDefinition()方法的示例:

示例 1:

// Java program to demonstrate
// getTimeDefinition() 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(17),
                      ZoneOffset.ofTotalSeconds(12));
  
        // getting value of TimeDefinition
        // by using getTimeDefinition() method
        ZoneOffsetTransitionRule.TimeDefinition
            time
            = zonetrans1.getTimeDefinition();
  
        // display the result
        System.out.println(
            "TimeDefinition : " + time);
    }
}
输出:
TimeDefinition : STANDARD

示例 2:

// Java program to demonstrate
// getTimeDefinition() 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.UTC,
                      ZoneOffset.ofTotalSeconds(8),
                      ZoneOffset.ofTotalSeconds(17),
                      ZoneOffset.ofTotalSeconds(12));
  
        // getting value of TimeDefinition
        // by using getTimeDefinition() method
        ZoneOffsetTransitionRule.TimeDefinition
            time
            = zonetrans1.getTimeDefinition();
  
        // display the result
        System.out.println(
            "TimeDefinition : " + time);
    }
}
输出:
TimeDefinition : UTC

参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/zone/ZoneOffsetTransitionRule.html#getTimeDefinition–