setStartRule(int, int, int): This method is available in java.util.SimpleTimeZone class of Java.
Syntax:
void java.util.SimpleTimeZone.setStartRule(int startMonth, int startDay, int startTime)
This method takes three arguments. This method sets the daylight saving time start rule to a fixed date within a month.
Parameters: Three parameters are required for this method.
startMonth: The daylight saving time starting month.
startDay: The day of the month on which the daylight saving time starts.
startTime: The daylight saving time starting time in local wall clock time.
Returns: NA
Throws:
IllegalArgumentException - if the startMonth,startDayOfMonth, or startTime parameters are out of range.
Approach 1: When no exception
Java
import java.util.SimpleTimeZone;public class SimpleTimeZonesetStartRule {public static void main(String[] args) {SimpleTimeZone simpleTimeZone =new SimpleTimeZone(100, "India");int startMonth = 1, startDay = 1, startTime = 0;simpleTimeZone.setStartRule(startMonth,startDay, startTime);System.out.println(simpleTimeZone);}}
Output:
java.util.SimpleTimeZone[id=India,offset=100,dstSavings=3600000,useDaylight=false,startYear=0,startMode=1,startMonth=1,startDay=1,startDayOfWeek=0,startTime=0,startTimeMode=0,endMode=0,endMonth=0,endDay=0,endDayOfWeek=0,endTime=0,endTimeMode=0]
Approach 2: IllegalArgumentException
Java
import java.util.SimpleTimeZone;public class SimpleTimeZonesetStartRule {public static void main(String[] args) {SimpleTimeZone simpleTimeZone =new SimpleTimeZone(100, "India");int startMonth = 21, startDay = 1, startTime = 0;simpleTimeZone.setStartRule(startMonth,startDay, startTime);System.out.println(simpleTimeZone);}}
Output:
Exception in thread "main" java.lang.IllegalArgumentException: Illegal start month 21 at java.base/java.util.SimpleTimeZone.decodeStartRule(SimpleTimeZone.java:1384) at java.base/java.util.SimpleTimeZone.setStartRule(SimpleTimeZone.java:393) at java.base/java.util.SimpleTimeZone.setStartRule(SimpleTimeZone.java:414)
No comments:
Post a Comment