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("Initially 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()); }}
输出
Initially 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("Initially 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()); }}
输出
Initially DST saving value is = 3500000
DST saving value set to 4000000
Current DST saving value is = 4000000