📜  Java中的 SimpleTimeZone setStartRule(int, int, int) 方法及示例

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

Java中的 SimpleTimeZone setStartRule(int, int, int) 方法及示例

Java中 SimpleTimeZone 类setStartRule(int startofMonth , int startofDay , int startofTime ) 方法用于将夏令时的特定开始规则设置为给定月份内的固定日期。

句法:

public void setStartRule(int startofMonth, 
                              int startofDay, 
                              int startofTime)

参数:该方法接受三个参数:

  • startofMonth : Integer 类型,指夏令时的起始月份。
  • startofDay :这是整数类型,指的是夏令时的开始日期。
  • startofTime :这是Integer类型,指的是夏令时的开始时间。

返回值:该方法不返回任何值。

下面的程序说明了在Java中使用 setStartRule() 方法:
示例 1:

// Java code to demonstrate
// setStartRule() method
  
import java.util.*;
  
public class SimpleTimeZone_Demo {
    public static void main(String[] args)
    {
  
        // Creating SimpleTimeZone object
        SimpleTimeZone simtimeobj
            = new SimpleTimeZone(100, "GMT");
  
        // Displaying the Initial value
        System.out.println(
            "Initial value: " + simtimeobj);
  
        // Setting an StartRule
        simtimeobj.setStartRule(Calendar.APRIL,
                                28, 3600000);
  
        // Displaying the New value
        System.out.println(
            "New value: " + simtimeobj);
    }
}
输出:
Initial value: java.util.SimpleTimeZone[id=GMT, offset=100, dstSavings=3600000,
useDaylight=false, startYear=0, startMode=0, startMonth=0, startDay=0, startDayOfWeek=0,
startTime=0, startTimeMode=0, endMode=0, endMonth=0, endDay=0, endDayOfWeek=0, endTime=0,
endTimeMode=0]

New value: java.util.SimpleTimeZone[id=GMT, offset=100, dstSavings=3600000,
useDaylight=false, startYear=0, startMode=1, startMonth=3, startDay=28, startDayOfWeek=0,
startTime=3600000, startTimeMode=0, endMode=0, endMonth=0, endDay=0, endDayOfWeek=0,
endTime=0, endTimeMode=0]

示例 2:

// Java code to demonstrate
// setStartRule() method
  
import java.util.*;
  
public class SimpleTimeZone_Demo {
    public static void main(String[] args)
    {
  
        // Creating SimpleTimeZone object
        SimpleTimeZone simtimeobj
            = new SimpleTimeZone(120, "GMT");
  
        // Displaying the Initial value
        System.out.println(
            "Initial value: " + simtimeobj);
  
        // Setting an StartRule
        simtimeobj.setStartRule(Calendar.JANUARY,
                                15, 3600000);
  
        // Displaying the New value
        System.out.println(
            "New value: " + simtimeobj);
    }
}
输出:
Initial value: java.util.SimpleTimeZone[id=GMT, offset=120, dstSavings=3600000,
useDaylight=false, startYear=0, startMode=0, startMonth=0, startDay=0, startDayOfWeek=0,
startTime=0, startTimeMode=0, endMode=0, endMonth=0, endDay=0, endDayOfWeek=0, endTime=0,
endTimeMode=0]

New value: java.util.SimpleTimeZone[id=GMT, offset=120, dstSavings=3600000,
useDaylight=false, startYear=0, startMode=1, startMonth=0, startDay=15, startDayOfWeek=0,
startTime=3600000, startTimeMode=0, endMode=0, endMonth=0, endDay=0, endDayOfWeek=0,
endTime=0, endTimeMode=0]

参考: https: Java/util/SimpleTimeZone.html#setStartRule(int,int,int)