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


Java SimpleTimeZone setDSTSavings()用法及代碼示例


SimpleTimeZone類的setDSTSavings()方法用於設置夏令時期間時鍾提前的時間。計算以毫秒為單位。

用法:

public void setDSTSavings(int millisSavedDuringDST)

參數:該函數接受單個參數millisSavedDuringDST,該參數指定時間相對於標準時間提前的毫秒數。


返回值:該方法沒有返回值。

異常:該函數不會引發任何異常。

下麵的程序演示了上述函數:

示例1:

// program to demonstrate the 
// function SimpleTimeZone.setDSTSavings() 
  
import java.util.*; 
  
public class GFG { 
  
    public static void main(String[] args) 
    { 
        // create simple time zone object 
        SimpleTimeZone obj 
            = new SimpleTimeZone(-28800000, 
                                 "US", 
                                 Calendar.MAY, 
                                 1, 
                                 -Calendar.SUNDAY, 
                                 7200000, 
                                 Calendar.NOVEMBER, 
                                 -1, 
                                 Calendar.MONDAY, 
                                 7000000, 
                                 3500000); 
  
        // printing DST value 
        System.out.println("Inittally DST saving value is = "
                           + obj.getDSTSavings()); 
  
        // setting DST saving time on object obj 
        obj.setDSTSavings(6000000); 
        System.out.println("DST saving value "
                           + "set to 6000000"); 
  
        // printing DST value 
        System.out.println("Current DST saving value is = "
                           + obj.getDSTSavings()); 
    } 
}
輸出:
Inittally DST saving value is = 3500000
DST saving value set to 6000000
Current DST saving value is = 6000000

示例2:

// program to demonstrate the 
// function SimpleTimeZone.setDSTSavings() 
  
import java.util.*; 
  
public class GFG { 
  
    public static void main(String[] args) 
    { 
        // create simple time zone object 
        SimpleTimeZone obj 
            = new SimpleTimeZone(-28800000, 
                                 "US", 
                                 Calendar.MAY, 
                                 1, 
                                 -Calendar.MONDAY, 
                                 7200000, 
                                 Calendar.JULY, 
                                 -1, 
                                 Calendar.MONDAY, 
                                 7000000, 
                                 3500000); 
  
        // printing DST value 
        System.out.println("Inittally DST saving value is = "
                           + obj.getDSTSavings()); 
  
        // setting DST saving time on object obj 
        obj.setDSTSavings(4000000); 
        System.out.println("DST saving value "
                           + "set to 4000000"); 
  
        // printing DST value 
        System.out.println("Current DST saving value is = "
                           + obj.getDSTSavings()); 
    } 
}
輸出:
Inittally DST saving value is = 3500000
DST saving value set to 4000000
Current DST saving value is = 4000000


相關用法


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