setEndRule(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 endTime)
This method takes three arguments. This method sets the daylight saving time end rule to a fixed date within a month.
Parameters: Three 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.
endTime: The daylight saving ending time in local wall clock time,(in milliseconds within the day) which is local daylight time in this case.
Throws:
IllegalArgumentException - the endMonth, endDay, or endTime parameters are out of range.
Approach 1: When no exception
Java
import java.util.SimpleTimeZone;public class SimpleTimeZonesetEndRule {public static void main(String[] args) {SimpleTimeZone simpleTimeZone =new SimpleTimeZone(100, "India");int endMonth = 5, endDay = 12, endTime = 18;simpleTimeZone.setEndRule(endMonth, endDay, 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=1,endMonth=5,endDay=12,endDayOfWeek=0,endTime=18,endTimeMode=0]
Approach 2: IllegalArgumentException
Java
import java.util.SimpleTimeZone;public class SimpleTimeZonesetEndRule {public static void main(String[] args) {SimpleTimeZone simpleTimeZone =new SimpleTimeZone(100, "India");int endMonth = 13, endDay = 12, endTime = 18;simpleTimeZone.setEndRule(endMonth, endDay, endTime);System.out.println(simpleTimeZone);}}
Output:
Exception in thread "main" java.lang.IllegalArgumentException: Illegal end month 13 at java.base/java.util.SimpleTimeZone.decodeEndRule(SimpleTimeZone.java:1431) at java.base/java.util.SimpleTimeZone.setEndRule(SimpleTimeZone.java:474) at java.base/java.util.SimpleTimeZone.setEndRule(SimpleTimeZone.java:496)
No comments:
Post a Comment