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
@version
1.49 01/12/04
@author
David Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu
Constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID with no daylight saving time schedule.
Parameters
rawOffsetThe base time zone offset in milliseconds to GMT.
IDThe time zone name that is given to this instance.
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
rawOffsetThe given base time zone offset from GMT.
IDThe time zone ID which is given to this object.
startMonthThe daylight saving time starting month. Month is a {@link Calendar#MONTH MONTH} field value (0-based. e.g., 0 for January).
startDayThe day of the month on which the daylight saving time starts. See the class description for the special cases of this parameter.
startDayOfWeekThe daylight saving time starting day-of-week. See the class description for the special cases of this parameter.
startTimeThe daylight saving time starting time in local wall clock time (in milliseconds within the day), which is local standard time in this case.
endMonthThe daylight saving time ending month. Month is a {@link Calendar#MONTH MONTH} field value (0-based. e.g., 9 for October).
endDayThe day of the month on which the daylight saving time ends. See the class description for the special cases of this parameter.
endDayOfWeekThe daylight saving time ending day-of-week. See the class description for the special cases of this parameter.
endTimeThe daylight saving ending time in local wall clock time, (in milliseconds within the day) which is local daylight time in this case.
Throws
IllegalArgumentExceptionif the month, day, dayOfWeek, or time parameters are out of range for the start or end rule
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
rawOffsetThe given base time zone offset from GMT.
IDThe time zone ID which is given to this object.
startMonthThe daylight saving time starting month. Month is a {@link Calendar#MONTH MONTH} field value (0-based. e.g., 0 for January).
startDayThe day of the month on which the daylight saving time starts. See the class description for the special cases of this parameter.
startDayOfWeekThe daylight saving time starting day-of-week. See the class description for the special cases of this parameter.
startTimeThe daylight saving time starting time in local wall clock time, which is local standard time in this case.
endMonthThe daylight saving time ending month. Month is a {@link Calendar#MONTH MONTH} field value (0-based. e.g., 9 for October).
endDayThe day of the month on which the daylight saving time ends. See the class description for the special cases of this parameter.
endDayOfWeekThe daylight saving time ending day-of-week. See the class description for the special cases of this parameter.
endTimeThe daylight saving ending time in local wall clock time, which is local daylight time in this case.
dstSavingsThe amount of time in milliseconds saved during daylight saving time.
Throws
IllegalArgumentExceptionif the month, day, dayOfWeek, or time parameters are out of range for the start or end rule
@since
1.2
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
rawOffsetThe given base time zone offset from GMT.
IDThe time zone ID which is given to this object.
startMonthThe daylight saving time starting month. Month is a {@link Calendar#MONTH MONTH} field value (0-based. e.g., 0 for January).
startDayThe day of the month on which the daylight saving time starts. See the class description for the special cases of this parameter.
startDayOfWeekThe daylight saving time starting day-of-week. See the class description for the special cases of this parameter.
startTimeThe daylight saving time starting time in the time mode specified by startTimeMode.
startTimeModeThe mode of the start time specified by startTime.
endMonthThe daylight saving time ending month. Month is a {@link Calendar#MONTH MONTH} field value (0-based. e.g., 9 for October).
endDayThe day of the month on which the daylight saving time ends. See the class description for the special cases of this parameter.
endDayOfWeekThe daylight saving time ending day-of-week. See the class description for the special cases of this parameter.
endTimeThe daylight saving ending time in time time mode specified by endTimeMode.
endTimeModeThe mode of the end time specified by endTime
dstSavingsThe amount of time in milliseconds saved during daylight saving time.
Throws
IllegalArgumentExceptionif 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
A style specifier for getDisplayName() indicating a long name, such as "Pacific Standard Time."
@since
1.2
See Also
A style specifier for getDisplayName() indicating a short name, such as "PST."
@since
1.2
See Also
Constant for a mode of start or end time specified as standard time.
@since
1.4
Constant for a mode of start or end time specified as UTC. European Union rules are specified as UTC time, for example.
@since
1.4
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.
@since
1.4
Returns a clone of this SimpleTimeZone instance.
Return
a clone of this instance.
Compares the equality of two SimpleTimeZone objects.
Parameters
objThe SimpleTimeZone object to be compared with.
Return
True if the given obj is the same as this SimpleTimeZone object; false otherwise.
Gets all the available IDs supported.
Return
an array of IDs.
Gets the available IDs according to the given time zone offset.
Parameters
rawOffsetthe given time zone GMT offset.
Return
an array of IDs, where the time zone for that ID has the specified GMT offset. For example, "America/Phoenix" and "America/Denver" both have GMT-07:00, but differ in daylight savings behavior.
Returns the runtime class of an object. That Class object is the object that is locked by static synchronized methods of the represented class.
Return
The java.lang.Class object that represents the runtime class of the object. The result is of type {@code Class} where X is the erasure of the static type of the expression on which getClass is called.
Gets the default TimeZone for this host. The source of the default TimeZone may vary with implementation.
Return
a default TimeZone.
See Also
Returns a name of this time zone suitable for presentation to the user in the default locale. This method returns the long name, not including daylight savings. If the display name is not available for the locale, then this method returns a string in the normalized custom ID format.
Return
the human-readable name of this time zone in the default locale.
@since
1.2
Returns a name of this time zone suitable for presentation to the user in the default locale. If the display name is not available for the locale, then this method returns a string in the normalized custom ID format.
Parameters
daylightif true, return the daylight savings name.
styleeither LONG or SHORT
Return
the human-readable name of this time zone in the default locale.
@since
1.2
Returns a name of this time zone suitable for presentation to the user in the specified locale. If the display name is not available for the locale, then this method returns a string in the normalized custom ID format.
Parameters
daylightif true, return the daylight savings name.
styleeither LONG or SHORT
localethe locale in which to supply the display name.
Return
the human-readable name of this time zone in the given locale or in the default locale if the given locale is not recognized.
Throws
IllegalArgumentExceptionstyle is invalid.
@since
1.2
Returns a name of this time zone suitable for presentation to the user in the specified locale. This method returns the long name, not including daylight savings. If the display name is not available for the locale, then this method returns a string in the normalized custom ID format.
Parameters
localethe locale in which to supply the display name.
Return
the human-readable name of this time zone in the given locale or in the default locale if the given locale is not recognized.
@since
1.2
Returns the amount of time in milliseconds that the clock is advanced during daylight saving time.
Return
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
Gets the ID of this time zone.
Return
the ID of this time zone.
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.

Parameters
eraThe era of the given date.
yearThe year in the given date.
monthThe month in the given date. Month is 0-based. e.g., 0 for January.
dayThe day-in-month of the given date.
dayOfWeekThe day-of-week of the given date.
millisThe milliseconds in day in standard local time.
Return
The milliseconds to add to UTC to get local time.
Throws
IllegalArgumentExceptionthe era, month, day, dayOfWeek, or millis parameters are out of range
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.
Parameters
datethe time at which the time zone offset is found
Return
the amount of time in milliseconds to add to UTC to get local time.
@since
1.4
Gets the GMT offset for this time zone.
Return
the GMT offset value in milliseconds
See Also
Gets the TimeZone for the given ID.
Parameters
IDthe ID for a TimeZone, either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a custom ID such as "GMT-8:00". Note that the support of abbreviations is for JDK 1.1.x compatibility only and full names should be used.
Return
the specified TimeZone, or the GMT zone if the given ID cannot be understood.
Generates the hash code for the SimpleDateFormat object.
Return
the hash code for this object
Returns true if this zone has the same rules and offset as another zone.
Parameters
otherthe TimeZone object to be compared with
Return
true if the given zone is a SimpleTimeZone and has the same rules and offset as this one
@since
1.2
Queries if the given date is in daylight saving time.
Return
true if daylight saving time is in effective at the given date; false otherwise.
Wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. A thread waits on an object's monitor by calling one of the wait methods.

The awakened thread will not be able to proceed until the current thread relinquishes the lock on this object. The awakened thread will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened thread enjoys no reliable privilege or disadvantage in being the next thread to lock this object.

This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways:

  • By executing a synchronized instance method of that object.
  • By executing the body of a synchronized statement that synchronizes on the object.
  • For objects of type Class, by executing a synchronized static method of that class.

Only one thread at a time can own an object's monitor.

Throws
IllegalMonitorStateExceptionif the current thread is not the owner of this object's monitor.
Wakes up all threads that are waiting on this object's monitor. A thread waits on an object's monitor by calling one of the wait methods.

The awakened threads will not be able to proceed until the current thread relinquishes the lock on this object. The awakened threads will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened threads enjoy no reliable privilege or disadvantage in being the next thread to lock this object.

This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.

Throws
IllegalMonitorStateExceptionif the current thread is not the owner of this object's monitor.
Sets the TimeZone that is returned by the getDefault method. If zone is null, reset the default to the value it had originally when the VM first started.
Parameters
zonethe new default time zone
See Also
Sets the amount of time in milliseconds that the clock is advanced during daylight saving time.
Parameters
millisSavedDuringDSTthe 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
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
endMonthThe daylight saving time ending month. Month is a {@link Calendar#MONTH MONTH} field value (0-based. e.g., 9 for October).
endDayThe day of the month on which the daylight saving time ends.
endTimeThe daylight saving ending time in local wall clock time, (in milliseconds within the day) which is local daylight time in this case.
Throws
IllegalArgumentExceptionthe endMonth, endDay, or endTime parameters are out of range
@since
1.2
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
endMonthThe daylight saving time ending month. Month is a {@link Calendar#MONTH MONTH} field value (0-based. e.g., 9 for October).
endDayThe day of the month on which the daylight saving time ends. See the class description for the special cases of this parameter.
endDayOfWeekThe daylight saving time ending day-of-week. See the class description for the special cases of this parameter.
endTimeThe daylight saving ending time in local wall clock time, (in milliseconds within the day) which is local daylight time in this case.
Throws
IllegalArgumentExceptionif the endMonth, endDay, endDayOfWeek, or endTime parameters are out of range
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
endMonthThe daylight saving time ending month. Month is a {@link Calendar#MONTH MONTH} field value (0-based. e.g., 9 for October).
endDayThe day of the month on which the daylight saving time ends.
endDayOfWeekThe daylight saving time ending day-of-week.
endTimeThe daylight saving ending time in local wall clock time, (in milliseconds within the day) which is local daylight time in this case.
afterIf 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
IllegalArgumentExceptionthe endMonth, endDay, endDayOfWeek, or endTime parameters are out of range
@since
1.2
Sets the time zone ID. This does not change any other data in the time zone object.
Parameters
IDthe new time zone ID.
Sets the base time zone offset to GMT. This is the offset to add to UTC to get local time.
See Also
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
startMonthThe daylight saving time starting month. Month is a {@link Calendar#MONTH MONTH} field value (0-based. e.g., 0 for January).
startDayThe day of the month on which the daylight saving time starts.
startTimeThe 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
IllegalArgumentExceptionif the startMonth, startDayOfMonth, or startTime parameters are out of range
@since
1.2
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
startMonthThe daylight saving time starting month. Month is a {@link Calendar#MONTH MONTH} field value (0-based. e.g., 0 for January).
startDayThe day of the month on which the daylight saving time starts. See the class description for the special cases of this parameter.
startDayOfWeekThe daylight saving time starting day-of-week. See the class description for the special cases of this parameter.
startTimeThe daylight saving time starting time in local wall clock time, which is local standard time in this case.
Throws
IllegalArgumentExceptionif the startMonth, startDay, startDayOfWeek, or startTime parameters are out of range
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
startMonthThe daylight saving time starting month. Month is a {@link Calendar#MONTH MONTH} field value (0-based. e.g., 0 for January).
startDayThe day of the month on which the daylight saving time starts.
startDayOfWeekThe daylight saving time starting day-of-week.
startTimeThe daylight saving time starting time in local wall clock time, which is local standard time in this case.
afterIf true, this rule selects the first dayOfWeek on or after dayOfMonth. If false, this rule selects the last dayOfWeek on or before dayOfMonth.
Throws
IllegalArgumentExceptionif the startMonth, startDay, startDayOfWeek, or startTime parameters are out of range
@since
1.2
Sets the daylight saving time starting year.
Parameters
yearThe daylight saving starting year.
Returns a string representation of this time zone.
Return
a string representation of this time zone.
Queries if this time zone uses daylight saving time.
Return
true if this time zone uses daylight saving time; false otherwise.
Causes current thread to wait until another thread invokes the method or the method for this object. In other words, this method behaves exactly as if it simply performs the call wait(0).

The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until another thread notifies threads waiting on this object's monitor to wake up either through a call to the notify method or the notifyAll method. The thread then waits until it can re-obtain ownership of the monitor and resumes execution.

As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:

     synchronized (obj) {
         while (<condition does not hold>)
             obj.wait();
         ... // Perform action appropriate to condition
     }
 
This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.
Throws
IllegalMonitorStateExceptionif the current thread is not the owner of the object's monitor.
InterruptedExceptionif another thread interrupted the current thread before or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown.
Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.

The current thread must own this object's monitor.

This method causes the current thread (call it T) to place itself in the wait set for this object and then to relinquish any and all synchronization claims on this object. Thread T becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:

  • Some other thread invokes the notify method for this object and thread T happens to be arbitrarily chosen as the thread to be awakened.
  • Some other thread invokes the notifyAll method for this object.
  • Some other thread interrupts thread T.
  • The specified amount of real time has elapsed, more or less. If timeout is zero, however, then real time is not taken into consideration and the thread simply waits until notified.
The thread T is then removed from the wait set for this object and re-enabled for thread scheduling. It then competes in the usual manner with other threads for the right to synchronize on the object; once it has gained control of the object, all its synchronization claims on the object are restored to the status quo ante - that is, to the situation as of the time that the wait method was invoked. Thread T then returns from the invocation of the wait method. Thus, on return from the wait method, the synchronization state of the object and of thread T is exactly as it was when the wait method was invoked.

A thread can also wake up without being notified, interrupted, or timing out, a so-called spurious wakeup. While this will rarely occur in practice, applications must guard against it by testing for the condition that should have caused the thread to be awakened, and continuing to wait if the condition is not satisfied. In other words, waits should always occur in loops, like this one:

     synchronized (obj) {
         while (<condition does not hold>)
             obj.wait(timeout);
         ... // Perform action appropriate to condition
     }
 
(For more information on this topic, see Section 3.2.3 in Doug Lea's "Concurrent Programming in Java (Second Edition)" (Addison-Wesley, 2000), or Item 50 in Joshua Bloch's "Effective Java Programming Language Guide" (Addison-Wesley, 2001).

If the current thread is interrupted by another thread while it is waiting, then an InterruptedException is thrown. This exception is not thrown until the lock status of this object has been restored as described above.

Note that the wait method, as it places the current thread into the wait set for this object, unlocks only this object; any other objects on which the current thread may be synchronized remain locked while the thread waits.

This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.

Parameters
timeoutthe maximum time to wait in milliseconds.
Throws
IllegalArgumentExceptionif the value of timeout is negative.
IllegalMonitorStateExceptionif the current thread is not the owner of the object's monitor.
InterruptedExceptionif another thread interrupted the current thread before or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown.
Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

This method is similar to the wait method of one argument, but it allows finer control over the amount of time to wait for a notification before giving up. The amount of real time, measured in nanoseconds, is given by:

 1000000*timeout+nanos

In all other respects, this method does the same thing as the method of one argument. In particular, wait(0, 0) means the same thing as wait(0).

The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until either of the following two conditions has occurred:

  • Another thread notifies threads waiting on this object's monitor to wake up either through a call to the notify method or the notifyAll method.
  • The timeout period, specified by timeout milliseconds plus nanos nanoseconds arguments, has elapsed.

The thread then waits until it can re-obtain ownership of the monitor and resumes execution.

As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:

     synchronized (obj) {
         while (<condition does not hold>)
             obj.wait(timeout, nanos);
         ... // Perform action appropriate to condition
     }
 
This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.
Parameters
timeoutthe maximum time to wait in milliseconds.
nanosadditional time, in nanoseconds range 0-999999.
Throws
IllegalArgumentExceptionif the value of timeout is negative or the value of nanos is not in the range 0-999999.
IllegalMonitorStateExceptionif the current thread is not the owner of this object's monitor.
InterruptedExceptionif another thread interrupted the current thread before or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown.