Sunday, September 22, 2024
Google search engine
HomeLanguagesJavaSimpleTimeZone setStartRule(int, int, int) method in Java with Examples

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

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)

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments