当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。