SimpleTimeZone类setStartRule()方法 (SimpleTimeZone Class setStartRule() method)
Syntax:
句法:
public void setStartRule(int st_mm, int st_dd, int st_time);
public void setStartRule(int st_mm, int st_dd, int st_dow, int st_time);
public void setStartRule(int st_mm, int st_dd,int st_dow, int st_time, boolean status);
setStartRule() method is available in java.util package.
setStartRule()方法在java.util包中可用。
setStartRule(int st_mm, int st_dd, int st_time) method is used to set the start rule of DST(Daylight Savings Time) to the given fixed date (dd) in a month.
setStartRule(int st_mm,int st_dd,int st_time)方法用于将DST(夏令时)的开始规则设置为一个月中的给定固定日期(dd)。
setStartRule(int st_mm, int st_dd,int st_dow, int st_time) method is used to set the start rule of DST(Daylight Savings Time).
setStartRule(int st_mm,int st_dd,int st_dow,int st_time)方法用于设置DST(夏令时)的开始规则。
setStartRule(int st_mm, int st_dd, int st_dow, int st_time, boolean status) method is used to set the start rule of DST(Daylight Savings Time) to the earlier weekday (dow) or after the given date (dd) in a month.
setStartRule(int st_mm,int st_dd,int st_dow,int st_time,boolean status)方法用于将DST(夏时制)的开始规则设置为较早的工作日(dow)或一个月中给定的日期(dd)之后。
These methods may throw an exception at the time of setting start rule.
这些方法在设置开始规则时可能会引发异常。
IllegalArgumentException: This exception may throw when any one of the parameters is not in a range.
IllegalArgumentException :当任何一个参数不在范围内时,可能引发此异常。
These are non-static methods and it is accessible with the class object only and if we try to access these methods with the class name then we will get an error.
这些是非静态方法,只能通过类对象访问,如果尝试使用类名称访问这些方法,则会收到错误消息。
Parameter(s):
参数:
In the first case, setStartRule(int st_mm, int st_dd, int st_time)
在第一种情况下, setStartRule(int st_mm,int st_dd,int st_time)
- int st_mm – represents the DST starting month.
- int st_mm –表示夏令时开始的月份。
- int st_dd – represents the DST starting day of month.
- int st_dd –表示夏令时开始的月份。
- int st_time – represents the DST starting time.
- int st_time –表示DST的开始时间。
In the second case, setStartRule(int st_mm, int st_dd, int st_dow, int st_time),
在第二种情况下, setStartRule(int st_mm,int st_dd,int st_dow,int st_time) ,
- int st_mm – represents the DST starting month.
- int st_mm –表示夏令时开始的月份。
- int st_dd – represents the DST starting day of month.
- int st_dd –表示夏令时开始的月份。
- int st_dow – represents the DST starting day of week.
- int st_dow –表示夏令时开始的星期几。
- int st_time – represents the DST starting time.
- int st_time –表示DST的开始时间。
In the second case, setStartRule(int st_mm, int st_dd,int st_dow, int st_time, boolean status),
在第二种情况下, setStartRule(int st_mm,int st_dd,int st_dow,int st_time,布尔状态) ,
- int st_mm – represents the DST starting month.
- int st_mm –表示夏令时开始的月份。
- int st_dd – represents the DST starting day of month.
- int st_dd –表示夏令时开始的月份。
- int st_dow – represents the DST starting day of week.
- int st_dow –表示夏令时开始的星期几。
- int st_time – represents the DST starting time.
- int st_time –表示DST的开始时间。
- boolean status – sets to true then this rule selects first st_dow on or after st_dd otherwise this rule selects last st_dow on or before st_dd.
- 布尔状态 –设置为true,然后此规则在st_dd或之后选择第一个st_dow,否则,在st_dd或之前选择最后一个st_dow。
Return value:
返回值:
In all cases, the return type of the method is void – It returns nothing.
在所有情况下,该方法的返回类型均为空 –它不返回任何内容。
Example:
例:
// Java program to demonstrate the example
// of setStartRule() method of SimpleTimeZone
import java.util.*;
public class SetStartRuleOfSimpleTimeZone {
public static void main(String args[]) {
// Instantiates SimpleTimeZone object
SimpleTimeZone s_tz1 = new SimpleTimeZone(360, "FRANCE");
SimpleTimeZone s_tz2 = new SimpleTimeZone(760, "JAPAN");
SimpleTimeZone s_tz3 = new SimpleTimeZone(39800000, "US",
Calendar.APRIL, 6, -Calendar.MONDAY, 7200000, Calendar.OCTOBER, -1,
Calendar.MONDAY, 7200000, 3600000);
// By using setStartRule(yy,mm,dd) method is used to
// set the DST start rule to a constant date
s_tz1.setStartRule(Calendar.JUNE, Calendar.MONDAY, 3800000);
// By using setStartRule(yy,mm,dow,dd) method is used to
// set the DST start rule to a weekday before
// or after the given date
s_tz2.setStartRule(Calendar.JUNE, Calendar.MONDAY, 2, 3800000, false);
// By using setStartRule(yy,mm,dow,dd,boolean) method is used to
// set the DST start rule
s_tz3.setStartRule(Calendar.JUNE, Calendar.MONDAY, 2, 3800000);
// Display SimpleTimeZone
System.out.print("s_tz1.setStartRule(Calendar.JUNE, Calendar.MONDAY,3800000): ");
System.out.println(s_tz1);
System.out.print("s_tz2.setStartRule(Calendar.JUNE, Calendar.MONDAY,3800000,false): ");
System.out.println(s_tz1);
System.out.print("s_tz3.setStartRule(Calendar.JUNE, Calendar.MONDAY,2,3800000): ");
System.out.println(s_tz1);
}
}
Output
输出量
s_tz1.setStartRule(Calendar.JUNE, Calendar.MONDAY,3800000): java.util.SimpleTimeZone[id=FRANCE,offset=360,dstSavings=3600000,useDaylight=false,startYear=0,startMode=1,startMonth=5,startDay=2,startDayOfWeek=0,startTime=3800000,startTimeMode=0,endMode=0,endMonth=0,endDay=0,endDayOfWeek=0,endTime=0,endTimeMode=0]
s_tz2.setStartRule(Calendar.JUNE, Calendar.MONDAY,3800000,false): java.util.SimpleTimeZone[id=FRANCE,offset=360,dstSavings=3600000,useDaylight=false,startYear=0,startMode=1,startMonth=5,startDay=2,startDayOfWeek=0,startTime=3800000,startTimeMode=0,endMode=0,endMonth=0,endDay=0,endDayOfWeek=0,endTime=0,endTimeMode=0]
s_tz3.setStartRule(Calendar.JUNE, Calendar.MONDAY,2,3800000): java.util.SimpleTimeZone[id=FRANCE,offset=360,dstSavings=3600000,useDaylight=false,startYear=0,startMode=1,startMonth=5,startDay=2,startDayOfWeek=0,startTime=3800000,startTimeMode=0,endMode=0,endMonth=0,endDay=0,endDayOfWeek=0,endTime=0,endTimeMode=0]
翻译自: https://www.includehelp.com/java/simpletimezone-setstartrule-method-with-example.aspx