SimpleTimeZone类setEndRule()方法 (SimpleTimeZone Class setEndRule() method)
Syntax:
句法:
public void setEndRule(int en_mm, int en_dd, int en_time);
public void setEndRule(int en_mm, int en_dd, int en_dow, int en_time);
public void setEndRule(int en_mm, int en_dd,int en_dow, int en_time, boolean status);
setEndRule() method is available in java.util package.
setEndRule()方法在java.util包中可用。
setEndRule(int en_mm, int en_dd, int en_time) method is used to set the ending rule of DST(Daylight Savings Time) to the given fixed date (dd) in a month.
setEndRule(int en_mm,int en_dd,int en_time)方法用于将DST(夏令时)的结束规则设置为一个月中的给定固定日期(dd)。
setEndRule(int en_mm, int en_dd,int en_dow, int en_time) method is used to set the end rule of DST(Daylight Savings Time).
setEndRule(int en_mm,int en_dd,int en_dow,int en_time)方法用于设置DST(夏令时)的结束规则。
setEndRule(int en_mm, int en_dd, int en_dow, int en_time, boolean status) method is used to set the ending rule of DST(Daylight Savings Time) to the earlier weekday (dow) or after the given date (dd) in a month.
setEndRule(int en_mm,int en_dd,int en_dow,int en_time,布尔状态)方法用于将DST(夏令时)的结束规则设置为较早的工作日(dow)或一个月中给定日期(dd)之后。
These methods may throw an exception at the time of setting end 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, setEndRule(int en_mm, int en_dd,int en_time)
在第一种情况下, setEndRule(int en_mm,int en_dd,int en_time)
- int en_mm – represents the DST ending month.
- int en_mm –表示夏令时结束的月份。
- int en_dd – represents the DST ending day of month.
- int en_dd –表示夏令时结束的月份。
- int en_time – represents the DST ending time.
- int en_time –表示DST的结束时间。
In the second case, setEndRule(int en_mm, int en_dd,int en_dow,int en_time),
在第二种情况下, setEndRule(int en_mm,int en_dd,int en_dow,int en_time) ,
- int en_mm – represents the DST ending month.
- int en_mm –表示夏令时结束的月份。
- int en_dd – represents the DST ending day of month.
- int en_dd –表示夏令时结束的月份。
- int en_dow – represents DST last day of week.
- int en_dow –表示夏令时。
- int en_time – represents the DST ending time.
- int en_time –表示DST的结束时间。
In the second case, setEndRule(int en_mm, int en_dd,int en_dow,int en_time,boolean status),
在第二种情况下, setEndRule(int en_mm,int en_dd,int en_dow,int en_time,布尔值状态) ,
- int en_mm – represents the DST ending month.
- int en_mm –表示夏令时结束的月份。
- int en_dd – represents the DST ending day of month.
- int en_dd –表示夏令时结束的月份。
- int en_dow – represents DST last day of week.
- int en_dow –表示夏令时。
- int en_time – represents the DST ending time.
- int en_time –表示DST的结束时间。
- boolean status – sets to true then this rule selects first en_dow on or after en_dd otherwise this rule selects last en_dow on or before en_dd.
- 布尔状态 –设置为true,然后此规则选择在en_dd或之后的第一个en_dow,否则该规则选择在en_dd或之前的最后一个en_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 setEndRule() method of SimpleTimeZone
import java.util.*;
public class SetEndRuleOfSimpleTimeZone {
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 setEndRule() method is used to
// set the DST end rule to a constant date
s_tz1.setEndRule(Calendar.JUNE, Calendar.MONDAY, 3800000);
// By using setEndRule() method is used to
// set the DST end rule to a weekday before
// or after the given date
s_tz2.setEndRule(Calendar.JUNE, Calendar.MONDAY, 2, 3800000, false);
// By using setEndRule() method is used to
// set the DST end rule
s_tz3.setEndRule(Calendar.JUNE, Calendar.MONDAY, 2, 3800000);
// Display SimpleTimeZone
System.out.print("s_tz1.setEndRule(Calendar.JUNE, Calendar.MONDAY,3800000): ");
System.out.println(s_tz1);
System.out.print("s_tz2.setEndRule(Calendar.JUNE, Calendar.MONDAY,3800000,false): ");
System.out.println(s_tz1);
System.out.print("s_tz3.setEndRule(Calendar.JUNE, Calendar.MONDAY,2,3800000): ");
System.out.println(s_tz1);
}
}
Output
输出量
s_tz1.setEndRule(Calendar.JUNE, Calendar.MONDAY,3800000): java.util.SimpleTimeZone[id=FRANCE,offset=360,dstSavings=3600000,useDaylight=false,startYear=0,startMode=0,startMonth=0,startDay=0,startDayOfWeek=0,startTime=0,startTimeMode=0,endMode=1,endMonth=5,endDay=2,endDayOfWeek=0,endTime=3800000,endTimeMode=0]
s_tz2.setEndRule(Calendar.JUNE, Calendar.MONDAY,3800000,false): java.util.SimpleTimeZone[id=FRANCE,offset=360,dstSavings=3600000,useDaylight=false,startYear=0,startMode=0,startMonth=0,startDay=0,startDayOfWeek=0,startTime=0,startTimeMode=0,endMode=1,endMonth=5,endDay=2,endDayOfWeek=0,endTime=3800000,endTimeMode=0]
s_tz3.setEndRule(Calendar.JUNE, Calendar.MONDAY,2,3800000): java.util.SimpleTimeZone[id=FRANCE,offset=360,dstSavings=3600000,useDaylight=false,startYear=0,startMode=0,startMonth=0,startDay=0,startDayOfWeek=0,startTime=0,startTimeMode=0,endMode=1,endMonth=5,endDay=2,endDayOfWeek=0,endTime=3800000,endTimeMode=0]
翻译自: https://www.includehelp.com/java/simpletimezone-setendrule-method-with-example.aspx