Java SimpleTimeZone setEndRule() Example

SimpleTimeZone class setEndRule() method example. This example shows you how to use setEndRule() method.


Syntax is : public void setEndRule(int endMonth, int endDay, int endTime)
Method sets the daylight saving time end rule to a fixed date within a month. This method is equivalent to:setEndRule(endMonth, endDay, 0, endTime)

Here is the code.
/**
 * @(#) SetEndRuleSimpleTimeZone.java
 * A class representing use of method setEndRule() of SimpleTimeZone
 class in java.util Package.
 * @Version  23-May-2008
 @author   Rose India Team
 */
import java.util.*;

class SetEndRuleSimpleTimeZone {
   public static void mainString args[] ){
        // Constructor of SimpleTimeZone class
     SimpleTimeZone obj = new SimpleTimeZone(-28800000,
      "America/Los_Angeles", Calendar.APRIL, 1,-Calendar.SUNDAY, 7200000,
      Calendar.OCTOBER, -1, Calendar.SUNDAY, 72000003600000);
     System.out.println("Object obj has values : \n" + obj);
        // setEndRule() method call.
      obj.setEndRuleCalendar.MAY, 23600000);
    System.out.println("Set end rules successfully!");
        System.out.println("New object has values : \n" + obj);
  }
}
/* Note: Method changes end rules for this object SimpleTimeZone(int rawOffset,
String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int 
startTimeMode, int endMonth, int endDay, int endDayOfWeek, int endTime, int 
endTimeMode, int dstSavings).
##  Another constructor of SimpleTimeZone class.
For example: // Base GMT offset: -8:00
             // DST starts:      at 2:00am in standard time
             //                  on the first Sunday in April
             // DST ends:        at 2:00am in daylight time
             //                  on the last Sunday in October
             // Save:            1 hour
SimpleTimeZone(-28800000, "America/Los_Angeles", calendar.APRIL, 1,-Calendar.
SUNDAY, 7200000, Calendar.OCTOBER, -1, Calendar.SUNDAY, 7200000, 3600000)
There are some rules to pass the values of arguments in constructor:
# Exact day of month
   To specify an exact day of month, set the month and day-of-month to an exact
   value, and day-of-week to zero. For example, to specify March 1, set the 
   month to MARCH, day-of-month to 1, and day-of-week to 0.
# Day of week on or after day of month
   To specify a day of week on or after an exact day of month, set the month to
   an exact month value, day-of-month to the day on or after which the rule is 
   applied, and day-of-week to a negative DAY_OF_WEEK field value. For example,
   to specify the second Sunday of April, set month to APRIL,day-of-month to 8,
   and day-of-week to -SUNDAY.
# Day of week on or before day of month
   To specify a day of the week on or before an exact day of the month, set 
   day-of-month and day-of-week to a negative value. For example, to specify 
   the last Wednesday on or before the 21st of March, set month to MARCH, 
   day-of-month is -21 and day-of-week is -WEDNESDAY.
# Last day-of-week of month
   To specify, the last day-of-week of the month, set day-of-week to a 
   DAY_OF_WEEK value and day-of-month to -1. For example, to specify the last 
   Sunday of October, set month to OCTOBER, day-of-week to SUNDAY and 
   day-of-month to -1. */

Output of the program.
Object obj has values :
java.util.SimpleTimeZone[id=America/Los_Angeles,offset=-28800000,dstSavings=3600000,
useDaylight=true,startYear=0,startMode=3,startMonth=3,startDay=1,startDayOfWeek=1,
startTime=7200000,startTimeMode=0,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,
endTime=7200000,endTimeMode=0]

Set end rules successfully!

New object has values :
java.util.SimpleTimeZone[id=America/Los_Angeles,offset=-28800000,dstSavings=3600000
,useDaylight=true,startYear=0,startMode=3,startMonth=3,startDay=1,startDayOfWeek=1,
startTime=7200000,startTimeMode=0,endMode=1,endMonth=4,endDay=2,endDayOfWeek=0,
endTime=3600000,endTimeMode=0]

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US