Open In App

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

Improve
Improve
Like Article
Like
Save
Share
Report

The setStartRule(int startofMonth, int startofDay, int startofTime) method of SimpleTimeZone class in Java is used to set a particular start rule of the day-light saving time to a fixed date within a given month.

Syntax:

public void setStartRule(int startofMonth, 
                              int startofDay, 
                              int startofTime)

Parameters: The method takes three parameters:

  • startofMonth: This is of Integer type and refers to the Starting month of the daylight saving time.
  • startofDay: This is of Integer type and refers to the Starting day of the daylight saving time.
  • startofTime: This is of Integer type and refers to the Starting time of the daylight saving time.

Return Value: The method does not return any value.

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




// Java code to demonstrate
// setStartRule() 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 StartRule
        simtimeobj.setStartRule(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=1, startMonth=3, startDay=28, startDayOfWeek=0,
startTime=3600000, startTimeMode=0, endMode=0, endMonth=0, endDay=0, endDayOfWeek=0,
endTime=0, endTimeMode=0]

Example 2:




// Java code to demonstrate
// setStartRule() 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 StartRule
        simtimeobj.setStartRule(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=1, startMonth=0, startDay=15, startDayOfWeek=0,
startTime=3600000, startTimeMode=0, endMode=0, endMonth=0, endDay=0, endDayOfWeek=0,
endTime=0, endTimeMode=0]

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



Last Updated : 27 Mar, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads