Home »
Java programming language
Java SimpleTimeZone setStartRule() Method with Example
SimpleTimeZone Class setStartRule() method: Here, we are going to learn about the setStartRule() method of SimpleTimeZone Class with its syntax and example.
Submitted by Preeti Jain, on March 12, 2020
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(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_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, 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.
- 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.
- 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)
- int st_mm – represents the DST starting month.
- int st_dd – represents the DST starting day of month.
- int st_time – represents the DST starting time.
-
In the second case, setStartRule(int st_mm, int st_dd, int st_dow, int st_time),
- int st_mm – represents the DST starting month.
- int st_dd – represents the DST starting day of month.
- int st_dow – represents the DST starting day of week.
- int st_time – represents the DST starting time.
-
In the second case, setStartRule(int st_mm, int st_dd,int st_dow, int st_time, boolean status),
- int st_mm – represents the DST starting month.
- int st_dd – represents the DST starting day of month.
- int st_dow – represents the DST starting day of week.
- int st_time – represents the DST starting time.
- 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.
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]