SimpleTimeZone setEndRule(int, int, int) method in Java with Examples

The setEndRule(int endofMonth, int endofDay, int endofTime) method of SimpleTimeZone class in Java is used to set a particular rule of the day-light saving time to a fixed date within a given month.

Syntax:

public void setEndRule(int endofMonth, 
                            int endofDay, 
                            int endofTime)

Parameters: The method takes three parameters:



  • endofMonth: This is of Integer type and refers to the ending month of the daylight saving time.
  • endofDay: This is of Integer type and refers to the ending day of the daylight saving time.
  • endofTime: This is of Integer type and refers to the ending time of the daylight saving time.

Return Value: The method does not return any value.

Below programs illustrate the use of setEndRule() Method in Java:
Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to demonstrate
// setEndRule() 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 EnDRule
        simtimeobj.setEndRule(Calendar.APRIL,
                              28, 3600000);
  
        // Displaying the New value
        System.out.println(
            "New value: " + simtimeobj);
    }
}

chevron_right


Output:

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=0, startMonth=0, startDay=0, startDayOfWeek=0,
startTime=0, startTimeMode=0, endMode=1, endMonth=3, endDay=28, endDayOfWeek=0,
endTime=3600000, endTimeMode=0]

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to demonstrate
// setEndRule() 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 EnDRule
        simtimeobj.setEndRule(Calendar.JANUARY,
                              15, 3600000);
  
        // Displaying the New value
        System.out.println(
            "New value: " + simtimeobj);
    }
}

chevron_right


Output:

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=0, startMonth=0, startDay=0, startDayOfWeek=0,
startTime=0, startTimeMode=0, endMode=1, endMonth=0, endDay=15, endDayOfWeek=0,
endTime=3600000, endTimeMode=0]

Reference: https://docs.oracle.com/javase/10/docs/api/java/util/SimpleTimeZone.html#setEndRule(int,int,int)



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.