setEndRule(int, int, int, int): This method is available in java.util.SimpleTimeZone class of Java.
Syntax:
void java.util.SimpleTimeZone.setEndRule(int endMonth, int endDay, int endDayOfWeek, int endTime)
This method takes four arguments. This method sets the daylight saving time end rule.
Parameters: Four parameters are required for this method.
endMonth: The daylight saving time ending month.
endDay: The day of the month on which the daylight saving time ends.
endDayOfWeek: The daylight saving time ending day-of-week.
endTime: The daylight saving ending time in the local wall clock time.
Throws:
IllegalArgumentException - if the endMonth, endDay, endDayOfWeek, or endTime parameters are out of range
Approach 1: When no exception
Java
import java.util.SimpleTimeZone;public class SimpleTimeZonesetEndRule2 {public static void main(String[] args) {SimpleTimeZone simpleTimeZone =new SimpleTimeZone(100, "India");int endMonth = 5, endDay = 2,endDayOfWeek = 2, endTime = 18;simpleTimeZone.setEndRule(endMonth,endDay, endDayOfWeek, endTime);System.out.println(simpleTimeZone);}}
Output:
java.util.SimpleTimeZone[id=India,offset=100,dstSavings=3600000,useDaylight=false,startYear=0,startMode=0,startMonth=0,startDay=0,startDayOfWeek=0,startTime=0,startTimeMode=0,endMode=2,endMonth=5,endDay=2,endDayOfWeek=2,endTime=18,endTimeMode=0]
Approach 2: IllegalArgumentException
Java
import java.util.SimpleTimeZone;public class SimpleTimeZonesetEndRule2 {public static void main(String[] args) {SimpleTimeZone simpleTimeZone =new SimpleTimeZone(100, "India");int endMonth = 15, endDay = 2,endDayOfWeek = 2, endTime = 18;simpleTimeZone.setEndRule(endMonth,endDay, endDayOfWeek, endTime);System.out.println(simpleTimeZone);}}
Output:
Exception in thread "main" java.lang.IllegalArgumentException: Illegal end month 15 at java.base/java.util.SimpleTimeZone.decodeEndRule(SimpleTimeZone.java:1431) at java.base/java.util.SimpleTimeZone.setEndRule(SimpleTimeZone.java:474)
No comments:
Post a Comment