Home » Java programming language

Java SimpleTimeZone setEndRule() Method with Example

SimpleTimeZone Class setEndRule() method: Here, we are going to learn about the setEndRule() method of SimpleTimeZone Class with its syntax and example.
Submitted by Preeti Jain, on March 12, 2020

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(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_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, 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.
  • 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.
  • 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)
    • int en_mm – represents the DST ending month.
    • int en_dd – represents the DST ending day of month.
    • int en_time – represents the DST ending time.
  • In the second case, setEndRule(int en_mm, int en_dd,int en_dow,int en_time),
    • int en_mm – represents the DST ending month.
    • int en_dd – represents the DST ending day of month.
    • int en_dow – represents DST last day of week.
    • int en_time – represents the DST ending time.
  • In the second case, setEndRule(int en_mm, int en_dd,int en_dow,int en_time,boolean status),
    • int en_mm – represents the DST ending month.
    • int en_dd – represents the DST ending day of month.
    • int en_dow – represents DST last day of week.
    • int en_time – represents the DST ending time.
    • 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.

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]


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.