當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java ZoneOffsetTransitionRule getOffsetBefore()用法及代碼示例

java.time.zone.ZoneOffsetTransitionRule類的getOffsetBefore()方法用於在過渡開始的特定瞬間獲取區域偏移量的對象。

用法:

public ZoneOffset getOffsetBefore()

參數:此方法不接受任何參數。

返回值:此方法在過渡開始的特定時刻返回區域偏移的對象。

下麵是說明getOffsetBefore()方法的示例:



範例1:

// Java program to demonstrate 
// getOffsetBefore() 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 Zone offset 
        // by using getOffsetBefore() method 
        ZoneOffset off 
            = zonetrans1.getOffsetBefore(); 
  
        // display the result 
        System.out.println( 
            "Zone Offset before:" + off); 
    } 
}
輸出:
Zone Offset before:+00:00:10

範例2:

// Java program to demonstrate 
// getOffsetBefore() 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 object of Zone offset 
        // by using getOffsetBefore() method 
        ZoneOffset off 
            = zonetrans1.getOffsetBefore(); 
  
        // display the result 
        System.out.println( 
            "Zone Offset before:" + off); 
    } 
}
輸出:
Zone Offset before:+00:00:17

參考: https://docs.oracle.com/javase/9/docs/api/java/time/zone/ZoneOffsetTransitionRule.html#getOffsetBefore-




相關用法


注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 ZoneOffsetTransitionRule getOffsetBefore() method in Java with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。