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

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:




// 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);
    }
}


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:




// 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);
    }
}


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)

RELATED ARTICLES

5 COMMENTS

Most Popular

Dominic
32737 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7119 POSTS0 COMMENTS
Nicole Veronica
12251 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12334 POSTS0 COMMENTS
Shaida Kate Naidoo
7228 POSTS0 COMMENTS
Ted Musemwa
7490 POSTS0 COMMENTS
Thapelo Manthata
7208 POSTS0 COMMENTS
Umr Jansen
7180 POSTS0 COMMENTS