java.util

Class SimpleTimeZone

Implemented Interfaces:
Cloneable, Serializable

public class SimpleTimeZone
extends TimeZone

SimpleTimeZone is a concrete subclass of TimeZone that represents a time zone for use with a Gregorian calendar. The class holds an offset from GMT, called raw offset, and start and end rules for a daylight saving time schedule. Since it only holds single values for each, it cannot handle historical changes in the offset from GMT and the daylight saving schedule, except that the setStartYear method can specify the year when the daylight saving time schedule starts in effect.

To construct a SimpleTimeZone with a daylight saving time schedule, the schedule can be described with a set of rules, start-rule and end-rule. A day when daylight saving time starts or ends is specified by a combination of month, day-of-month, and day-of-week values. The month value is represented by a Calendar MONTH field value, such as Calendar.MARCH. The day-of-week value is represented by a Calendar DAY_OF_WEEK value, such as SUNDAY. The meanings of value combinations are as follows.

The time of the day at which daylight saving time starts or ends is specified by a millisecond value within the day. There are three kinds of modes to specify the time: WALL_TIME, STANDARD_TIME and UTC_TIME. For example, if daylight saving time ends at 2:00 am in the wall clock time, it can be specified by 7200000 milliseconds in the WALL_TIME mode. In this case, the wall clock time for an end-rule means the same thing as the daylight time.

The following are examples of parameters for constructing time zone objects.


      // 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)

      // Base GMT offset: +1:00
      // DST starts:      at 1:00am in UTC time
      //                  on the last Sunday in March
      // DST ends:        at 1:00am in UTC time
      //                  on the last Sunday in October
      // Save:            1 hour
      SimpleTimeZone(3600000,
                     "Europe/Paris",
                     Calendar.MARCH, -1, Calendar.SUNDAY,
                     3600000, SimpleTimeZone.UTC_TIME,
                     Calendar.OCTOBER, -1, Calendar.SUNDAY,
                     3600000, SimpleTimeZone.UTC_TIME,
                     3600000)
 
These parameter rules are also applicable to the set rule methods, such as setStartRule.
Since:
1.1
See Also:
Calendar, GregorianCalendar, TimeZone, Serialized Form

Field Summary

static int
STANDARD_TIME
Constant for a mode of start or end time specified as standard time.
static int
UTC_TIME
Constant for a mode of start or end time specified as UTC.
static int
WALL_TIME
Constant for a mode of start or end time specified as wall clock time.

Fields inherited from class java.util.TimeZone

LONG, SHORT

Constructor Summary

SimpleTimeZone(int rawOffset, String ID)
Constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID with no daylight saving time schedule.
SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime)
Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time.
SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime, int dstSavings)
Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time.
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)
Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time.

Method Summary

Object
clone()
Returns a clone of this SimpleTimeZone instance.
boolean
equals(Object obj)
Compares the equality of two SimpleTimeZone objects.
int
getDSTSavings()
Returns the amount of time in milliseconds that the clock is advanced during daylight saving time.
int
getOffset(int era, int year, int month, int day, int dayOfWeek, int millis)
Returns the difference in milliseconds between local time and UTC, taking into account both the raw offset and the effect of daylight saving, for the specified date and time.
int
getOffset(long date)
Returns the offset of this time zone from UTC at the given time.
int
getRawOffset()
Gets the GMT offset for this time zone.
boolean
hasSameRules(TimeZone other)
Returns true if this zone has the same rules and offset as another zone.
int
hashCode()
Generates the hash code for the SimpleDateFormat object.
boolean
inDaylightTime(Date date)
Queries if the given date is in daylight saving time.
void
setDSTSavings(int millisSavedDuringDST)
Sets the amount of time in milliseconds that the clock is advanced during daylight saving time.
void
setEndRule(int endMonth, int endDay, int endTime)
Sets the daylight saving time end rule to a fixed date within a month.
void
setEndRule(int endMonth, int endDay, int endDayOfWeek, int endTime)
Sets the daylight saving time end rule.
void
setEndRule(int endMonth, int endDay, int endDayOfWeek, int endTime, boolean after)
Sets the daylight saving time end rule to a weekday before or after the given date within a month, e.g., the first Monday on or after the 8th.
void
setRawOffset(int offsetMillis)
Sets the base time zone offset to GMT.
void
setStartRule(int startMonth, int startDay, int startTime)
Sets the daylight saving time start rule to a fixed date within a month.
void
setStartRule(int startMonth, int startDay, int startDayOfWeek, int startTime)
Sets the daylight saving time start rule.
void
setStartRule(int startMonth, int startDay, int startDayOfWeek, int startTime, boolean after)
Sets the daylight saving time start rule to a weekday before or after the given date within a month, e.g., the first Monday on or after the 8th.
void
setStartYear(int year)
Sets the daylight saving time starting year.
String
toString()
Returns a string representation of this time zone.
boolean
useDaylightTime()
Queries if this time zone uses daylight saving time.

Methods inherited from class java.util.TimeZone

clone, getAvailableIDs, getAvailableIDs, getDSTSavings, getDefault, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getID, getOffset, getOffset, getRawOffset, getTimeZone, hasSameRules, inDaylightTime, setDefault, setID, setRawOffset, useDaylightTime

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

STANDARD_TIME

public static final int STANDARD_TIME
Constant for a mode of start or end time specified as standard time.
Field Value:
1
Since:
1.4

UTC_TIME

public static final int UTC_TIME
Constant for a mode of start or end time specified as UTC. European Union rules are specified as UTC time, for example.
Field Value:
2
Since:
1.4

WALL_TIME

public static final int WALL_TIME
Constant for a mode of start or end time specified as wall clock time. Wall clock time is standard time for the onset rule, and daylight time for the end rule.
Field Value:
0
Since:
1.4

Constructor Details

SimpleTimeZone

public SimpleTimeZone(int rawOffset,
                      String ID)
Constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID with no daylight saving time schedule.
Parameters:
rawOffset - The base time zone offset in milliseconds to GMT.
ID - The time zone name that is given to this instance.
Usages and Demos :

View More Examples of SimpleTimeZone(int rawOffset,String ID)
   1:       try {
   2:     SimpleTimeZone gmt = new SimpleTimeZone(0, "GMT");
   3:     System.out.println("PASSED: timezone="+gmt.toString());
   4:       } catch (Exception e) {
   5:     System.out.println("FAILED: "+e);

View Full Code Here
   1:     String datePart;
   2:     Calendar calendar = Calendar.getInstance(new SimpleTimeZone(0,"GMT"));
   3:     
   4:     DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
   5:     datePart =  dateFormat.format(calendar.getTime());

View Full Code Here
   1: 
   2:         SimpleTimeZone est = new SimpleTimeZone(-5 * 60 * 60 * 1000, timezoneIDs[0]);
   3: 
   4:         est.setStartRule (Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
   5:         est.setEndRule (Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);

View Full Code Here
   1:     {
   2:         SimpleTimeZone      tz = new SimpleTimeZone(0, "Z");
   3:         SimpleDateFormat    dateF = new SimpleDateFormat("yyyyMMddHHmmss");
   4: 
   5:         dateF.setTimeZone(tz);

View Full Code Here
   1: 
   2:         dateF.setTimeZone(new SimpleTimeZone(0,"Z"));
   3: 
   4:         this.time = dateF.format(time);
   5:     }

View Full Code Here

SimpleTimeZone

public SimpleTimeZone(int rawOffset,
                      String ID,
                      int startMonth,
                      int startDay,
                      int startDayOfWeek,
                      int startTime,
                      int endMonth,
                      int endDay,
                      int endDayOfWeek,
                      int endTime)
Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time. Both startTime and endTime are specified to be represented in the wall clock time. The amount of daylight saving is assumed to be 3600000 milliseconds (i.e., one hour). This constructor is equivalent to:

     SimpleTimeZone(rawOffset,
                    ID,
                    startMonth,
                    startDay,
                    startDayOfWeek,
                    startTime,
                    SimpleTimeZone.WALL_TIME,
                    endMonth,
                    endDay,
                    endDayOfWeek,
                    endTime,
                    SimpleTimeZone.WALL_TIME,
                    3600000)
 
Parameters:
rawOffset - The given base time zone offset from GMT.
ID - The time zone ID which is given to this object.
startMonth - The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January).
startDay - The day of the month on which the daylight saving time starts. See the class description for the special cases of this parameter.
startDayOfWeek - The daylight saving time starting day-of-week. See the class description for the special cases of this parameter.
startTime - The daylight saving time starting time in local wall clock time (in milliseconds within the day), which is local standard time in this case.
endMonth - The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October).
endDay - The day of the month on which the daylight saving time ends. See the class description for the special cases of this parameter.
endDayOfWeek - The daylight saving time ending day-of-week. See the class description for the special cases of this parameter.
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 - if the month, day, dayOfWeek, or time parameters are out of range for the start or end rule

SimpleTimeZone

public SimpleTimeZone(int rawOffset,
                      String ID,
                      int startMonth,
                      int startDay,
                      int startDayOfWeek,
                      int startTime,
                      int endMonth,
                      int endDay,
                      int endDayOfWeek,
                      int endTime,
                      int dstSavings)
Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time. Both startTime and endTime are assumed to be represented in the wall clock time. This constructor is equivalent to:

     SimpleTimeZone(rawOffset,
                    ID,
                    startMonth,
                    startDay,
                    startDayOfWeek,
                    startTime,
                    SimpleTimeZone.WALL_TIME,
                    endMonth,
                    endDay,
                    endDayOfWeek,
                    endTime,
                    SimpleTimeZone.WALL_TIME,
                    dstSavings)
 
Parameters:
rawOffset - The given base time zone offset from GMT.
ID - The time zone ID which is given to this object.
startMonth - The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January).
startDay - The day of the month on which the daylight saving time starts. See the class description for the special cases of this parameter.
startDayOfWeek - The daylight saving time starting day-of-week. See the class description for the special cases of this parameter.
startTime - The daylight saving time starting time in local wall clock time, which is local standard time in this case.
endMonth - The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October).
endDay - The day of the month on which the daylight saving time ends. See the class description for the special cases of this parameter.
endDayOfWeek - The daylight saving time ending day-of-week. See the class description for the special cases of this parameter.
endTime - The daylight saving ending time in local wall clock time, which is local daylight time in this case.
dstSavings - The amount of time in milliseconds saved during daylight saving time.
Throws:
IllegalArgumentException - if the month, day, dayOfWeek, or time parameters are out of range for the start or end rule
Since:
1.2

SimpleTimeZone

public 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)
Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time. This constructor takes the full set of the start and end rules parameters, including modes of startTime and endTime. The mode specifies either wall time or standard time or UTC time.
Parameters:
rawOffset - The given base time zone offset from GMT.
ID - The time zone ID which is given to this object.
startMonth - The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January).
startDay - The day of the month on which the daylight saving time starts. See the class description for the special cases of this parameter.
startDayOfWeek - The daylight saving time starting day-of-week. See the class description for the special cases of this parameter.
startTime - The daylight saving time starting time in the time mode specified by startTimeMode.
startTimeMode - The mode of the start time specified by startTime.
endMonth - The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October).
endDay - The day of the month on which the daylight saving time ends. See the class description for the special cases of this parameter.
endDayOfWeek - The daylight saving time ending day-of-week. See the class description for the special cases of this parameter.
endTime - The daylight saving ending time in time time mode specified by endTimeMode.
endTimeMode - The mode of the end time specified by endTime
dstSavings - The amount of time in milliseconds saved during daylight saving time.
Throws:
IllegalArgumentException - if the month, day, dayOfWeek, time more, or time parameters are out of range for the start or end rule, or if a time mode value is invalid.
Since:
1.4

Method Details

clone

public Object clone()
Returns a clone of this SimpleTimeZone instance.
Overrides:
clone in interface TimeZone
Returns:
a clone of this instance.

equals

public boolean equals(Object obj)
Compares the equality of two SimpleTimeZone objects.
Overrides:
equals in interface Object
Parameters:
obj - The SimpleTimeZone object to be compared with.
Returns:
True if the given obj is the same as this SimpleTimeZone object; false otherwise.

getDSTSavings

public int getDSTSavings()
Returns the amount of time in milliseconds that the clock is advanced during daylight saving time.
Overrides:
getDSTSavings in interface TimeZone
Returns:
the number of milliseconds the time is advanced with respect to standard time when the daylight saving rules are in effect, or 0 (zero) if this time zone doesn't observe daylight saving time.
Since:
1.2
Usages and Demos :

View More Examples of getDSTSavings()
   1: import jp.ujihara.java.util.Locale;
   2: import jp.ujihara.java.util.SimpleTimeZone;
   3: import jp.ujihara.java.util.TimeZone;
   4:         ...
   5:                     offset = 0;
   6:                     if (k > 2 && tz instanceof SimpleTimeZone)
   7:                       {
   8:         ...
   9:                         SimpleTimeZone stz = (SimpleTimeZone) tz;
  10:         ...
  11:                         offset = stz.getDSTSavings();

View Full Code Here

getOffset

public int getOffset(int era,
                     int year,
                     int month,
                     int day,
                     int dayOfWeek,
                     int millis)
Returns the difference in milliseconds between local time and UTC, taking into account both the raw offset and the effect of daylight saving, for the specified date and time. This method assumes that the start and end month are distinct. It also uses a default GregorianCalendar object as its underlying calendar, such as for determining leap years. Do not use the result of this method with a calendar other than a default GregorianCalendar.

Note: In general, clients should use Calendar.get(ZONE_OFFSET) + Calendar.get(DST_OFFSET) instead of calling this method.

Overrides:
getOffset in interface TimeZone
Parameters:
era - The era of the given date.
year - The year in the given date.
month - The month in the given date. Month is 0-based. e.g., 0 for January.
day - The day-in-month of the given date.
dayOfWeek - The day-of-week of the given date.
millis - The milliseconds in day in standard local time.
Returns:
The milliseconds to add to UTC to get local time.
Throws:
IllegalArgumentException - the era, month, day, dayOfWeek, or millis parameters are out of range

getOffset

public int getOffset(long date)
Returns the offset of this time zone from UTC at the given time. If daylight saving time is in effect at the given time, the offset value is adjusted with the amount of daylight saving.
Overrides:
getOffset in interface TimeZone
Parameters:
date - the time at which the time zone offset is found
Returns:
the amount of time in milliseconds to add to UTC to get local time.
Since:
1.4

getRawOffset

public int getRawOffset()
Gets the GMT offset for this time zone.
Overrides:
getRawOffset in interface TimeZone
Returns:
the GMT offset value in milliseconds
Usages and Demos :

View More Examples of getRawOffset()
   1: import java.util.HashMap;
   2: import java.util.SimpleTimeZone;
   3: import java.util.TimeZone;
   4:         ...
   5: 
   6:     SimpleTimeZone tz = getLastRule();
   7:     if (tz != null) {
   8:         ...
   9:         int rawoffset = tz.getRawOffset();
  10:         long msec = date;
  11:         ...
  12: 
  13:     SimpleTimeZone tz = getLastRule();

View Full Code Here

hasSameRules

public boolean hasSameRules(TimeZone other)
Returns true if this zone has the same rules and offset as another zone.
Overrides:
hasSameRules in interface TimeZone
Parameters:
other - the TimeZone object to be compared with
Returns:
true if the given zone is a SimpleTimeZone and has the same rules and offset as this one
Since:
1.2

hashCode

public int hashCode()
Generates the hash code for the SimpleDateFormat object.
Overrides:
hashCode in interface Object
Returns:
the hash code for this object

inDaylightTime

public boolean inDaylightTime(Date date)
Queries if the given date is in daylight saving time.
Overrides:
inDaylightTime in interface TimeZone
Returns:
true if daylight saving time is in effective at the given date; false otherwise.
Usages and Demos :

View More Examples of inDaylightTime(Date date)
   1: import java.util.HashMap;
   2: import java.util.SimpleTimeZone;
   3: import java.util.TimeZone;
   4:         ...
   5: 
   6:     SimpleTimeZone tz = getLastRule();
   7:     if (tz != null) {
   8:         ...
   9: 
  10:     SimpleTimeZone tz = getLastRule();
  11:     if (tz != null) {
  12:         ...
  13:         return tz.inDaylightTime(date);

View Full Code Here

setDSTSavings

public void setDSTSavings(int millisSavedDuringDST)
Sets the amount of time in milliseconds that the clock is advanced during daylight saving time.
Parameters:
millisSavedDuringDST - the number of milliseconds the time is advanced with respect to standard time when the daylight saving time rules are in effect. A positive number, typically one hour (3600000).
Since:
1.2

setEndRule

public void setEndRule(int endMonth,
                       int endDay,
                       int endTime)
Sets the daylight saving time end rule to a fixed date within a month. This method is equivalent to:
setEndRule(endMonth, endDay, 0, endTime)
Parameters:
endMonth - The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October).
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
Since:
1.2

setEndRule

public void setEndRule(int endMonth,
                       int endDay,
                       int endDayOfWeek,
                       int endTime)
Sets the daylight saving time end rule. For example, if daylight saving time ends on the last Sunday in October at 2 am in wall clock time, you can set the end rule by calling: setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*60*60*1000);
Parameters:
endMonth - The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October).
endDay - The day of the month on which the daylight saving time ends. See the class description for the special cases of this parameter.
endDayOfWeek - The daylight saving time ending day-of-week. See the class description for the special cases of this parameter.
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 - if the endMonth, endDay, endDayOfWeek, or endTime parameters are out of range
Usages and Demos :

View More Examples of setEndRule(int endMonth,int endDay,int endDayOfWeek,int endTime)
   1: import java.util.TimeZone;
   2: import java.util.SimpleTimeZone;
   3: import java.util.GregorianCalendar;
   4:         ...
   5: 
   6:         SimpleTimeZone est = new SimpleTimeZone (-5 * 60 * 60 * 1000, timezoneIDs[0]);
   7: 
   8:         ...
   9:         est.setStartRule (Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
  10:         est.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);

View Full Code Here
   1:       System.exit(0);
   2:     SimpleTimeZone edt = new SimpleTimeZone(-5 * 60 * 60 * 1000, ids[0]);
   3:     edt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
   4:         ...
   5:     edt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
   6:     thecal = new GregorianCalendar(edt);
   7:     Date trialTime = new Date();
   8:     thecal.setTime(trialTime);

View Full Code Here
   1: 
   2:         SimpleTimeZone pdt = new SimpleTimeZone((hours * 60+minutes) * 60 * 1000, ids[0]);
   3: 
   4:         ...
   5:         pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
   6:         pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
   7: 
   8:         Calendar calendar = new GregorianCalendar(pdt);
   9:         return calendar;

View Full Code Here
   1: import java.util.Locale;
   2: import java.util.SimpleTimeZone;
   3: import java.util.TimeZone;
   4:         ...
   5:       String[] ids = TimeZone.getAvailableIDs(+1 * 60 * 60 * 1000);
   6:       SimpleTimeZone cet = new SimpleTimeZone(+1 * 60 * 60 * 1000, ids[0]);
   7:       Date now = new Date();
   8:         ...
   9:       cet.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
  10:       cet.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
  11:       cal = new GregorianCalendar(cet);

View Full Code Here
   1:         
   2:         SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000,  "America/Los_Angeles");
   3: 
   4:         ...
   5:         pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 *  60 * 1000);
   6:         pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
   7: 
   8:         ncal = new GregorianCalendar(pdt);
   9:         ncal.set(Calendar.MILLISECOND, 0);

View Full Code Here

setEndRule

public void setEndRule(int endMonth,
                       int endDay,
                       int endDayOfWeek,
                       int endTime,
                       boolean after)
Sets the daylight saving time end rule to a weekday before or after the given date within a month, e.g., the first Monday on or after the 8th.
Parameters:
endMonth - The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October).
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 local wall clock time, (in milliseconds within the day) which is local daylight time in this case.
after - If true, this rule selects the first endDayOfWeek on or after endDay. If false, this rule selects the last endDayOfWeek on or before endDay of the month.
Throws:
IllegalArgumentException - the endMonth, endDay, endDayOfWeek, or endTime parameters are out of range
Since:
1.2

setRawOffset

public void setRawOffset(int offsetMillis)
Sets the base time zone offset to GMT. This is the offset to add to UTC to get local time.
Overrides:
setRawOffset in interface TimeZone
Usages and Demos :

View More Examples of setRawOffset(int offsetMillis)
   1: import java.text.ParseException;
   2: import java.util.SimpleTimeZone;
   3: import java.util.TimeZone;
   4:         ...
   5:         SimpleDateFormat df = new SimpleDateFormat(YEAR_FORMAT);
   6:         SimpleTimeZone timeZone = new SimpleTimeZone(0,"UTC");
   7: 
   8:         ...
   9:             offset = isZoneNegative() ? -offset : offset;
  10:             timeZone.setRawOffset(offset);
  11:             timeZone.setID(TimeZone.getAvailableIDs(offset)[0]);

View Full Code Here
   1: import java.text.ParseException;
   2: import java.util.SimpleTimeZone;
   3: import java.util.TimeZone;
   4:         ...
   5:         SimpleDateFormat df = new SimpleDateFormat(YEAR_FORMAT);
   6:         SimpleTimeZone timeZone = new SimpleTimeZone(0,"UTC");
   7: 
   8:         ...
   9:             offset = isZoneNegative() ? -offset : offset;
  10:             timeZone.setRawOffset(offset);
  11:             timeZone.setID(TimeZone.getAvailableIDs(offset)[0]);

View Full Code Here
   1: import java.text.SimpleDateFormat;
   2: import java.util.SimpleTimeZone;
   3: 
   4:         ...
   5:         SimpleDateFormat df = new SimpleDateFormat(MONTH_FORMAT);
   6:         SimpleTimeZone timeZone = new SimpleTimeZone(0,"UTC");
   7: 
   8:         ...
   9:             offset = isZoneNegative() ? -offset : offset;
  10:             timeZone.setRawOffset(offset);
  11:             timeZone.setID(TimeZone.getAvailableIDs(offset)[0]);

View Full Code Here
   1: import java.text.ParseException;
   2: import java.util.SimpleTimeZone;
   3: import java.util.TimeZone;
   4:         ...
   5:         if ( isUTC() ) {
   6:             SimpleTimeZone timeZone = new SimpleTimeZone(0,"UTC");
   7:             int offset = 0;
   8:         ...
   9:             offset = isZoneNegative() ? -offset : offset;
  10:             timeZone.setRawOffset(offset);
  11:             timeZone.setID(TimeZone.getAvailableIDs(offset)[0]);

View Full Code Here
   1: import java.text.ParseException;
   2: import java.util.SimpleTimeZone;
   3: import java.util.TimeZone;
   4:         ...
   5:         if ( isUTC() ) {
   6:             SimpleTimeZone timeZone = new SimpleTimeZone(0,"UTC");
   7:             int offset = 0;
   8:         ...
   9:             offset = isZoneNegative() ? -offset : offset;
  10:             timeZone.setRawOffset(offset);
  11:             timeZone.setID(TimeZone.getAvailableIDs(offset)[0]);

View Full Code Here

setStartRule

public void setStartRule(int startMonth,
                         int startDay,
                         int startTime)
Sets the daylight saving time start rule to a fixed date within a month. This method is equivalent to:
setStartRule(startMonth, startDay, 0, startTime)
Parameters:
startMonth - The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January).
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, which is local standard time in this case. See the class description for the special cases of this parameter.
Throws:
IllegalArgumentException - if the startMonth, startDayOfMonth, or startTime parameters are out of range
Since:
1.2

setStartRule

public void setStartRule(int startMonth,
                         int startDay,
                         int startDayOfWeek,
                         int startTime)
Sets the daylight saving time start rule. For example, if daylight saving time starts on the first Sunday in April at 2 am in local wall clock time, you can set the start rule by calling:
setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2*60*60*1000);
Parameters:
startMonth - The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January).
startDay - The day of the month on which the daylight saving time starts. See the class description for the special cases of this parameter.
startDayOfWeek - The daylight saving time starting day-of-week. See the class description for the special cases of this parameter.
startTime - The daylight saving time starting time in local wall clock time, which is local standard time in this case.
Throws:
IllegalArgumentException - if the startMonth, startDay, startDayOfWeek, or startTime parameters are out of range
Usages and Demos :

View More Examples of setStartRule(int startMonth,int startDay,int startDayOfWeek,int startTime)
   1: import java.util.TimeZone;
   2: import java.util.SimpleTimeZone;
   3: import java.util.GregorianCalendar;
   4:         ...
   5: 
   6:         SimpleTimeZone est = new SimpleTimeZone (-5 * 60 * 60 * 1000, timezoneIDs[0]);
   7: 
   8:         ...
   9:         est.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
  10:         est.setEndRule (Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);

View Full Code Here
   1:       System.exit(0);
   2:     SimpleTimeZone edt = new SimpleTimeZone(-5 * 60 * 60 * 1000, ids[0]);
   3:         ...
   4:     edt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
   5:     edt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
   6:     thecal = new GregorianCalendar(edt);
   7:     Date trialTime = new Date();

View Full Code Here
   1: 
   2:         SimpleTimeZone pdt = new SimpleTimeZone((hours * 60+minutes) * 60 * 1000, ids[0]);
   3: 
   4:         ...
   5:         pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
   6:         pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
   7: 
   8:         Calendar calendar = new GregorianCalendar(pdt);

View Full Code Here
   1: import java.util.Locale;
   2: import java.util.SimpleTimeZone;
   3: import java.util.TimeZone;
   4:         ...
   5:       String[] ids = TimeZone.getAvailableIDs(+1 * 60 * 60 * 1000);
   6:       SimpleTimeZone cet = new SimpleTimeZone(+1 * 60 * 60 * 1000, ids[0]);
   7:       Date now = new Date();
   8:         ...
   9:       DateFormat fmt;
  10:       cet.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
  11:       cet.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);

View Full Code Here
   1:         
   2:         SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000,  "America/Los_Angeles");
   3: 
   4:         ...
   5:         pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 *  60 * 1000);
   6:         pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
   7: 
   8:         ncal = new GregorianCalendar(pdt);

View Full Code Here

setStartRule

public void setStartRule(int startMonth,
                         int startDay,
                         int startDayOfWeek,
                         int startTime,
                         boolean after)
Sets the daylight saving time start rule to a weekday before or after the given date within a month, e.g., the first Monday on or after the 8th.
Parameters:
startMonth - The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January).
startDay - The day of the month on which the daylight saving time starts.
startDayOfWeek - The daylight saving time starting day-of-week.
startTime - The daylight saving time starting time in local wall clock time, which is local standard time in this case.
after - If true, this rule selects the first dayOfWeek on or after dayOfMonth. If false, this rule selects the last dayOfWeek on or before dayOfMonth.
Throws:
IllegalArgumentException - if the startMonth, startDay, startDayOfWeek, or startTime parameters are out of range
Since:
1.2

setStartYear

public void setStartYear(int year)
Sets the daylight saving time starting year.
Parameters:
year - The daylight saving starting year.

toString

public String toString()
Returns a string representation of this time zone.
Overrides:
toString in interface Object
Returns:
a string representation of this time zone.

useDaylightTime

public boolean useDaylightTime()
Queries if this time zone uses daylight saving time.
Overrides:
useDaylightTime in interface TimeZone
Returns:
true if this time zone uses daylight saving time; false otherwise.