📌  相关文章
📜  Java中的 SimpleTimeZone setDSTSavings() 方法及示例

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

Java中的 SimpleTimeZone setDSTSavings() 方法及示例

SimpleTimeZone 类setDSTSavings()方法用于设置在夏令时期间时钟提前的时间量。计算以毫秒为单位完成。

句法:

public void setDSTSavings(int millisSavedDuringDST)

参数:该函数接受单个参数millisSavedDuringDST ,它指定时间相对于标准时间提前的毫秒数。

返回值:该方法没有返回值。

异常:该函数不抛出任何异常。

下面的程序演示了上述函数:

方案一:

// 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

方案二:

// 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