101 * transition schedule can be specified with a custom time zone ID. If
102 * the specified string doesn't match the syntax, <code>"GMT"</code>
103 * is used.
104 * <p>
105 * When creating a <code>TimeZone</code>, the specified custom time
106 * zone ID is normalized in the following syntax:
107 * <blockquote><pre>
108 * <a name="NormalizedCustomID"><i>NormalizedCustomID:</i></a>
109 * <code>GMT</code> <i>Sign</i> <i>TwoDigitHours</i> <code>:</code> <i>Minutes</i>
110 * <i>Sign:</i> one of
111 * <code>+ -</code>
112 * <i>TwoDigitHours:</i>
113 * <i>Digit</i> <i>Digit</i>
114 * <i>Minutes:</i>
115 * <i>Digit</i> <i>Digit</i>
116 * <i>Digit:</i> one of
117 * <code>0 1 2 3 4 5 6 7 8 9</code>
118 * </pre></blockquote>
119 * For example, TimeZone.getTimeZone("GMT-8").getID() returns "GMT-08:00".
120 *
121 * <h4>Three-letter time zone IDs</h4>
122 *
123 * For compatibility with JDK 1.1.x, some other three-letter time zone IDs
124 * (such as "PST", "CTT", "AST") are also supported. However, <strong>their
125 * use is deprecated</strong> because the same abbreviation is often used
126 * for multiple time zones (for example, "CST" could be U.S. "Central Standard
127 * Time" and "China Standard Time"), and the Java platform can then only
128 * recognize one of them.
129 *
130 *
131 * @see Calendar
132 * @see GregorianCalendar
133 * @see SimpleTimeZone
134 * @author Mark Davis, David Goldsmith, Chen-Lieh Huang, Alan Liu
135 * @since JDK1.1
136 */
137 abstract public class TimeZone implements Serializable, Cloneable {
138 /**
139 * Sole constructor. (For invocation by subclass constructors, typically
140 * implicit.)
141 */
287 }
288
289 /**
290 * Sets the time zone ID. This does not change any other data in
291 * the time zone object.
292 * @param ID the new time zone ID.
293 */
294 public void setID(String ID)
295 {
296 if (ID == null) {
297 throw new NullPointerException();
298 }
299 this.ID = ID;
300 }
301
302 /**
303 * Returns a long standard time name of this {@code TimeZone} suitable for
304 * presentation to the user in the default locale.
305 *
306 * <p>This method is equivalent to:
307 * <pre><blockquote>
308 * getDisplayName(false, {@link #LONG},
309 * Locale.getDefault({@link Locale.Category#DISPLAY}))
310 * </blockquote></pre>
311 *
312 * @return the human-readable name of this time zone in the default locale.
313 * @since 1.2
314 * @see #getDisplayName(boolean, int, Locale)
315 * @see Locale#getDefault(Locale.Category)
316 * @see Locale.Category
317 */
318 public final String getDisplayName() {
319 return getDisplayName(false, LONG,
320 Locale.getDefault(Locale.Category.DISPLAY));
321 }
322
323 /**
324 * Returns a long standard time name of this {@code TimeZone} suitable for
325 * presentation to the user in the specified {@code locale}.
326 *
327 * <p>This method is equivalent to:
328 * <pre><blockquote>
329 * getDisplayName(false, {@link #LONG}, locale)
330 * </blockquote></pre>
331 *
332 * @param locale the locale in which to supply the display name.
333 * @return the human-readable name of this time zone in the given locale.
334 * @exception NullPointerException if {@code locale} is {@code null}.
335 * @since 1.2
336 * @see #getDisplayName(boolean, int, Locale)
337 */
338 public final String getDisplayName(Locale locale) {
339 return getDisplayName(false, LONG, locale);
340 }
341
342 /**
343 * Returns a name in the specified {@code style} of this {@code TimeZone}
344 * suitable for presentation to the user in the default locale. If the
345 * specified {@code daylight} is {@code true}, a Daylight Saving Time name
346 * is returned (even if this {@code TimeZone} doesn't observe Daylight Saving
347 * Time). Otherwise, a Standard Time name is returned.
348 *
349 * <p>This method is equivalent to:
350 * <pre><blockquote>
351 * getDisplayName(daylight, style,
352 * Locale.getDefault({@link Locale.Category#DISPLAY}))
353 * </blockquote></pre>
354 *
355 * @param daylight {@code true} specifying a Daylight Saving Time name, or
356 * {@code false} specifying a Standard Time name
357 * @param style either {@link #LONG} or {@link #SHORT}
358 * @return the human-readable name of this time zone in the default locale.
359 * @exception IllegalArgumentException if {@code style} is invalid.
360 * @since 1.2
361 * @see #getDisplayName(boolean, int, Locale)
362 * @see Locale#getDefault(Locale.Category)
363 * @see Locale.Category
364 * @see java.text.DateFormatSymbols#getZoneStrings()
365 */
366 public final String getDisplayName(boolean daylight, int style) {
367 return getDisplayName(daylight, style,
368 Locale.getDefault(Locale.Category.DISPLAY));
369 }
370
371 /**
372 * Returns a name in the specified {@code style} of this {@code TimeZone}
373 * suitable for presentation to the user in the specified {@code
|
101 * transition schedule can be specified with a custom time zone ID. If
102 * the specified string doesn't match the syntax, <code>"GMT"</code>
103 * is used.
104 * <p>
105 * When creating a <code>TimeZone</code>, the specified custom time
106 * zone ID is normalized in the following syntax:
107 * <blockquote><pre>
108 * <a name="NormalizedCustomID"><i>NormalizedCustomID:</i></a>
109 * <code>GMT</code> <i>Sign</i> <i>TwoDigitHours</i> <code>:</code> <i>Minutes</i>
110 * <i>Sign:</i> one of
111 * <code>+ -</code>
112 * <i>TwoDigitHours:</i>
113 * <i>Digit</i> <i>Digit</i>
114 * <i>Minutes:</i>
115 * <i>Digit</i> <i>Digit</i>
116 * <i>Digit:</i> one of
117 * <code>0 1 2 3 4 5 6 7 8 9</code>
118 * </pre></blockquote>
119 * For example, TimeZone.getTimeZone("GMT-8").getID() returns "GMT-08:00".
120 *
121 * <h3>Three-letter time zone IDs</h3>
122 *
123 * For compatibility with JDK 1.1.x, some other three-letter time zone IDs
124 * (such as "PST", "CTT", "AST") are also supported. However, <strong>their
125 * use is deprecated</strong> because the same abbreviation is often used
126 * for multiple time zones (for example, "CST" could be U.S. "Central Standard
127 * Time" and "China Standard Time"), and the Java platform can then only
128 * recognize one of them.
129 *
130 *
131 * @see Calendar
132 * @see GregorianCalendar
133 * @see SimpleTimeZone
134 * @author Mark Davis, David Goldsmith, Chen-Lieh Huang, Alan Liu
135 * @since JDK1.1
136 */
137 abstract public class TimeZone implements Serializable, Cloneable {
138 /**
139 * Sole constructor. (For invocation by subclass constructors, typically
140 * implicit.)
141 */
287 }
288
289 /**
290 * Sets the time zone ID. This does not change any other data in
291 * the time zone object.
292 * @param ID the new time zone ID.
293 */
294 public void setID(String ID)
295 {
296 if (ID == null) {
297 throw new NullPointerException();
298 }
299 this.ID = ID;
300 }
301
302 /**
303 * Returns a long standard time name of this {@code TimeZone} suitable for
304 * presentation to the user in the default locale.
305 *
306 * <p>This method is equivalent to:
307 * <blockquote><pre>
308 * getDisplayName(false, {@link #LONG},
309 * Locale.getDefault({@link Locale.Category#DISPLAY}))
310 * </pre></blockquote>
311 *
312 * @return the human-readable name of this time zone in the default locale.
313 * @since 1.2
314 * @see #getDisplayName(boolean, int, Locale)
315 * @see Locale#getDefault(Locale.Category)
316 * @see Locale.Category
317 */
318 public final String getDisplayName() {
319 return getDisplayName(false, LONG,
320 Locale.getDefault(Locale.Category.DISPLAY));
321 }
322
323 /**
324 * Returns a long standard time name of this {@code TimeZone} suitable for
325 * presentation to the user in the specified {@code locale}.
326 *
327 * <p>This method is equivalent to:
328 * <blockquote><pre>
329 * getDisplayName(false, {@link #LONG}, locale)
330 * </pre></blockquote>
331 *
332 * @param locale the locale in which to supply the display name.
333 * @return the human-readable name of this time zone in the given locale.
334 * @exception NullPointerException if {@code locale} is {@code null}.
335 * @since 1.2
336 * @see #getDisplayName(boolean, int, Locale)
337 */
338 public final String getDisplayName(Locale locale) {
339 return getDisplayName(false, LONG, locale);
340 }
341
342 /**
343 * Returns a name in the specified {@code style} of this {@code TimeZone}
344 * suitable for presentation to the user in the default locale. If the
345 * specified {@code daylight} is {@code true}, a Daylight Saving Time name
346 * is returned (even if this {@code TimeZone} doesn't observe Daylight Saving
347 * Time). Otherwise, a Standard Time name is returned.
348 *
349 * <p>This method is equivalent to:
350 * <blockquote><pre>
351 * getDisplayName(daylight, style,
352 * Locale.getDefault({@link Locale.Category#DISPLAY}))
353 * </pre></blockquote>
354 *
355 * @param daylight {@code true} specifying a Daylight Saving Time name, or
356 * {@code false} specifying a Standard Time name
357 * @param style either {@link #LONG} or {@link #SHORT}
358 * @return the human-readable name of this time zone in the default locale.
359 * @exception IllegalArgumentException if {@code style} is invalid.
360 * @since 1.2
361 * @see #getDisplayName(boolean, int, Locale)
362 * @see Locale#getDefault(Locale.Category)
363 * @see Locale.Category
364 * @see java.text.DateFormatSymbols#getZoneStrings()
365 */
366 public final String getDisplayName(boolean daylight, int style) {
367 return getDisplayName(daylight, style,
368 Locale.getDefault(Locale.Category.DISPLAY));
369 }
370
371 /**
372 * Returns a name in the specified {@code style} of this {@code TimeZone}
373 * suitable for presentation to the user in the specified {@code
|