2 *******************************************************************************
\r
3 * Copyright (C) 1996-2008, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
8 package com.ibm.icu.text;
\r
10 import java.text.FieldPosition;
\r
11 import java.text.Format;
\r
12 import java.text.ParseException;
\r
13 import java.text.ParsePosition;
\r
14 import java.util.Date;
\r
15 import java.util.Locale;
\r
17 import com.ibm.icu.util.Calendar;
\r
18 import com.ibm.icu.util.TimeZone;
\r
19 import com.ibm.icu.util.ULocale;
\r
22 * DateFormat is an abstract class for date/time formatting subclasses which
\r
23 * formats and parses dates or time in a language-independent manner.
\r
24 * The date/time formatting subclass, such as SimpleDateFormat, allows for
\r
25 * formatting (i.e., date -> text), parsing (text -> date), and
\r
26 * normalization. The date is represented as a <code>Date</code> object or
\r
27 * as the milliseconds since January 1, 1970, 00:00:00 GMT.
\r
29 * <p>DateFormat provides many class methods for obtaining default date/time
\r
30 * formatters based on the default or a given loacle and a number of formatting
\r
31 * styles. The formatting styles include FULL, LONG, MEDIUM, and SHORT. More
\r
32 * detail and examples of using these styles are provided in the method
\r
35 * <p>DateFormat helps you to format and parse dates for any locale.
\r
36 * Your code can be completely independent of the locale conventions for
\r
37 * months, days of the week, or even the calendar format: lunar vs. solar.
\r
39 * <p>To format a date for the current Locale, use one of the
\r
40 * static factory methods:
\r
42 * myString = DateFormat.getDateInstance().format(myDate);
\r
44 * <p>If you are formatting multiple numbers, it is
\r
45 * more efficient to get the format and use it multiple times so that
\r
46 * the system doesn't have to fetch the information about the local
\r
47 * language and country conventions multiple times.
\r
49 * DateFormat df = DateFormat.getDateInstance();
\r
50 * for (int i = 0; i < a.length; ++i) {
\r
51 * output.println(df.format(myDate[i]) + "; ");
\r
54 * <p>To format a number for a different Locale, specify it in the
\r
55 * call to getDateInstance().
\r
57 * DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);
\r
59 * <p>You can use a DateFormat to parse also.
\r
61 * myDate = df.parse(myString);
\r
63 * <p>Use getDateInstance to get the normal date format for that country.
\r
64 * There are other static factory methods available.
\r
65 * Use getTimeInstance to get the time format for that country.
\r
66 * Use getDateTimeInstance to get a date and time format. You can pass in
\r
67 * different options to these factory methods to control the length of the
\r
68 * result; from SHORT to MEDIUM to LONG to FULL. The exact result depends
\r
69 * on the locale, but generally:
\r
70 * <ul><li>SHORT is completely numeric, such as 12.13.52 or 3:30pm
\r
71 * <li>MEDIUM is longer, such as Jan 12, 1952
\r
72 * <li>LONG is longer, such as January 12, 1952 or 3:30:32pm
\r
73 * <li>FULL is pretty completely specified, such as
\r
74 * Tuesday, April 12, 1952 AD or 3:30:42pm PST.
\r
77 * <p>You can also set the time zone on the format if you wish.
\r
78 * If you want even more control over the format or parsing,
\r
79 * (or want to give your users more control),
\r
80 * you can try casting the DateFormat you get from the factory methods
\r
81 * to a SimpleDateFormat. This will work for the majority
\r
82 * of countries; just remember to put it in a try block in case you
\r
83 * encounter an unusual one.
\r
85 * <p>You can also use forms of the parse and format methods with
\r
86 * ParsePosition and FieldPosition to
\r
88 * <ul><li>progressively parse through pieces of a string.
\r
89 * <li>align any particular field, or find out where it is for selection
\r
93 * <h4>Synchronization</h4>
\r
95 * Date formats are not synchronized. It is recommended to create separate
\r
96 * format instances for each thread. If multiple threads access a format
\r
97 * concurrently, it must be synchronized externally.
\r
100 * @see NumberFormat
\r
101 * @see SimpleDateFormat
\r
102 * @see com.ibm.icu.util.Calendar
\r
103 * @see com.ibm.icu.util.GregorianCalendar
\r
104 * @see com.ibm.icu.util.TimeZone
\r
105 * @author Mark Davis, Chen-Lieh Huang, Alan Liu
\r
108 public class DateFormat extends Format {
\r
109 private static final long serialVersionUID = 1;
\r
114 public final java.text.DateFormat dateFormat;
\r
118 * @param delegate the DateFormat to which to delegate
\r
120 public DateFormat(java.text.DateFormat delegate) {
\r
121 this.dateFormat = delegate;
\r
125 * For subclass use. Subclasses will generally not
\r
126 * work correctly unless they manipulate the delegate.
\r
128 protected DateFormat() {
\r
129 this.dateFormat = java.text.DateFormat.getInstance();
\r
133 * FieldPosition selector for 'G' field alignment,
\r
134 * corresponding to the {@link Calendar#ERA} field.
\r
137 public final static int ERA_FIELD = 0;
\r
140 * FieldPosition selector for 'y' field alignment,
\r
141 * corresponding to the {@link Calendar#YEAR} field.
\r
144 public final static int YEAR_FIELD = 1;
\r
147 * FieldPosition selector for 'M' field alignment,
\r
148 * corresponding to the {@link Calendar#MONTH} field.
\r
151 public final static int MONTH_FIELD = 2;
\r
154 * FieldPosition selector for 'd' field alignment,
\r
155 * corresponding to the {@link Calendar#DATE} field.
\r
158 public final static int DATE_FIELD = 3;
\r
161 * FieldPosition selector for 'k' field alignment,
\r
162 * corresponding to the {@link Calendar#HOUR_OF_DAY} field.
\r
163 * HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock.
\r
164 * For example, 23:59 + 01:00 results in 24:59.
\r
167 public final static int HOUR_OF_DAY1_FIELD = 4;
\r
170 * FieldPosition selector for 'H' field alignment,
\r
171 * corresponding to the {@link Calendar#HOUR_OF_DAY} field.
\r
172 * HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock.
\r
173 * For example, 23:59 + 01:00 results in 00:59.
\r
176 public final static int HOUR_OF_DAY0_FIELD = 5;
\r
179 * FieldPosition selector for 'm' field alignment,
\r
180 * corresponding to the {@link Calendar#MINUTE} field.
\r
183 public final static int MINUTE_FIELD = 6;
\r
186 * FieldPosition selector for 's' field alignment,
\r
187 * corresponding to the {@link Calendar#SECOND} field.
\r
190 public final static int SECOND_FIELD = 7;
\r
193 * FieldPosition selector for 'S' field alignment,
\r
194 * corresponding to the {@link Calendar#MILLISECOND} field.
\r
197 public final static int FRACTIONAL_SECOND_FIELD = 8;
\r
200 * Alias for FRACTIONAL_SECOND_FIELD.
\r
201 * @stable ICU 3.4.3
\r
203 public final static int MILLISECOND_FIELD = FRACTIONAL_SECOND_FIELD;
\r
206 * FieldPosition selector for 'E' field alignment,
\r
207 * corresponding to the {@link Calendar#DAY_OF_WEEK} field.
\r
210 public final static int DAY_OF_WEEK_FIELD = 9;
\r
213 * FieldPosition selector for 'D' field alignment,
\r
214 * corresponding to the {@link Calendar#DAY_OF_YEAR} field.
\r
217 public final static int DAY_OF_YEAR_FIELD = 10;
\r
220 * FieldPosition selector for 'F' field alignment,
\r
221 * corresponding to the {@link Calendar#DAY_OF_WEEK_IN_MONTH} field.
\r
224 public final static int DAY_OF_WEEK_IN_MONTH_FIELD = 11;
\r
227 * FieldPosition selector for 'w' field alignment,
\r
228 * corresponding to the {@link Calendar#WEEK_OF_YEAR} field.
\r
231 public final static int WEEK_OF_YEAR_FIELD = 12;
\r
234 * FieldPosition selector for 'W' field alignment,
\r
235 * corresponding to the {@link Calendar#WEEK_OF_MONTH} field.
\r
238 public final static int WEEK_OF_MONTH_FIELD = 13;
\r
241 * FieldPosition selector for 'a' field alignment,
\r
242 * corresponding to the {@link Calendar#AM_PM} field.
\r
245 public final static int AM_PM_FIELD = 14;
\r
248 * FieldPosition selector for 'h' field alignment,
\r
249 * corresponding to the {@link Calendar#HOUR} field.
\r
250 * HOUR1_FIELD is used for the one-based 12-hour clock.
\r
251 * For example, 11:30 PM + 1 hour results in 12:30 AM.
\r
254 public final static int HOUR1_FIELD = 15;
\r
257 * FieldPosition selector for 'K' field alignment,
\r
258 * corresponding to the {@link Calendar#HOUR} field.
\r
259 * HOUR0_FIELD is used for the zero-based 12-hour clock.
\r
260 * For example, 11:30 PM + 1 hour results in 00:30 AM.
\r
263 public final static int HOUR0_FIELD = 16;
\r
266 * FieldPosition selector for 'z' field alignment,
\r
267 * corresponding to the {@link Calendar#ZONE_OFFSET} and
\r
268 * {@link Calendar#DST_OFFSET} fields.
\r
271 public final static int TIMEZONE_FIELD = 17;
\r
274 * Overrides Format.
\r
275 * Formats a time object into a time string. Examples of time objects
\r
276 * are a time value expressed in milliseconds and a Date object.
\r
277 * @param obj must be a Number or a Date or a Calendar.
\r
278 * @param toAppendTo the string buffer for the returning time string.
\r
279 * @return the formatted time string.
\r
280 * @param fieldPosition keeps track of the position of the field
\r
281 * within the returned string.
\r
282 * On input: an alignment field,
\r
283 * if desired. On output: the offsets of the alignment field. For
\r
284 * example, given a time text "1996.07.10 AD at 15:08:56 PDT",
\r
285 * if the given fieldPosition is DateFormat.YEAR_FIELD, the
\r
286 * begin index and end index of fieldPosition will be set to
\r
287 * 0 and 4, respectively.
\r
288 * Notice that if the same time field appears
\r
289 * more than once in a pattern, the fieldPosition will be set for the first
\r
290 * occurence of that time field. For instance, formatting a Date to
\r
291 * the time string "1 PM PDT (Pacific Daylight Time)" using the pattern
\r
292 * "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD,
\r
293 * the begin index and end index of fieldPosition will be set to
\r
294 * 5 and 8, respectively, for the first occurence of the timezone
\r
295 * pattern character 'z'.
\r
296 * @see java.text.Format
\r
299 public final StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition fieldPosition) {
\r
300 if (obj instanceof Calendar) {
\r
301 return format((Calendar)obj, toAppendTo, fieldPosition);
\r
302 } else if (obj instanceof Date) {
\r
303 return format((Date)obj, toAppendTo, fieldPosition);
\r
304 } else if (obj instanceof Number) {
\r
305 return format(new Date(((Number)obj).longValue()), toAppendTo, fieldPosition );
\r
307 throw new IllegalArgumentException("Cannot format given Object as a Date");
\r
312 * Formats a date into a date/time string.
\r
313 * @param cal a Calendar set to the date and time to be formatted
\r
314 * into a date/time string.
\r
315 * @param toAppendTo the string buffer for the returning date/time string.
\r
316 * @param fieldPosition keeps track of the position of the field
\r
317 * within the returned string.
\r
318 * On input: an alignment field,
\r
319 * if desired. On output: the offsets of the alignment field. For
\r
320 * example, given a time text "1996.07.10 AD at 15:08:56 PDT",
\r
321 * if the given fieldPosition is DateFormat.YEAR_FIELD, the
\r
322 * begin index and end index of fieldPosition will be set to
\r
323 * 0 and 4, respectively.
\r
324 * Notice that if the same time field appears
\r
325 * more than once in a pattern, the fieldPosition will be set for the first
\r
326 * occurence of that time field. For instance, formatting a Date to
\r
327 * the time string "1 PM PDT (Pacific Daylight Time)" using the pattern
\r
328 * "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD,
\r
329 * the begin index and end index of fieldPosition will be set to
\r
330 * 5 and 8, respectively, for the first occurence of the timezone
\r
331 * pattern character 'z'.
\r
332 * @return the formatted date/time string.
\r
335 public StringBuffer format(Calendar cal, StringBuffer toAppendTo, FieldPosition fieldPosition) {
\r
336 return format(cal.getTime(), toAppendTo, fieldPosition);
\r
341 * Formats a Date into a date/time string.
\r
342 * @param date a Date to be formatted into a date/time string.
\r
343 * @param toAppendTo the string buffer for the returning date/time string.
\r
344 * @param fieldPosition keeps track of the position of the field
\r
345 * within the returned string.
\r
346 * On input: an alignment field,
\r
347 * if desired. On output: the offsets of the alignment field. For
\r
348 * example, given a time text "1996.07.10 AD at 15:08:56 PDT",
\r
349 * if the given fieldPosition is DateFormat.YEAR_FIELD, the
\r
350 * begin index and end index of fieldPosition will be set to
\r
351 * 0 and 4, respectively.
\r
352 * Notice that if the same time field appears
\r
353 * more than once in a pattern, the fieldPosition will be set for the first
\r
354 * occurence of that time field. For instance, formatting a Date to
\r
355 * the time string "1 PM PDT (Pacific Daylight Time)" using the pattern
\r
356 * "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD,
\r
357 * the begin index and end index of fieldPosition will be set to
\r
358 * 5 and 8, respectively, for the first occurence of the timezone
\r
359 * pattern character 'z'.
\r
360 * @return the formatted date/time string.
\r
363 public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
\r
364 return dateFormat.format(date, toAppendTo, fieldPosition);
\r
368 * Formats a Date into a date/time string.
\r
369 * @param date the time value to be formatted into a time string.
\r
370 * @return the formatted time string.
\r
373 public final String format(Date date) {
\r
374 return dateFormat.format(date);
\r
378 * Parse a date/time string.
\r
380 * @param text The date/time string to be parsed
\r
382 * @return A Date, or null if the input could not be parsed
\r
384 * @exception ParseException If the given string cannot be parsed as a date.
\r
386 * @see #parse(String, ParsePosition)
\r
389 public Date parse(String text) throws ParseException {
\r
390 return dateFormat.parse(text);
\r
394 * Parse a date/time string according to the given parse position.
\r
395 * For example, a time text "07/10/96 4:5 PM, PDT" will be parsed
\r
396 * into a Calendar that is equivalent to Date(837039928046). The
\r
397 * caller should clear the calendar before calling this method,
\r
398 * unless existing field information is to be kept.
\r
400 * <p> By default, parsing is lenient: If the input is not in the form used
\r
401 * by this object's format method but can still be parsed as a date, then
\r
402 * the parse succeeds. Clients may insist on strict adherence to the
\r
403 * format by calling setLenient(false).
\r
405 * @see #setLenient(boolean)
\r
407 * @param text The date/time string to be parsed
\r
409 * @param cal The calendar into which parsed data will be stored.
\r
410 * In general, this should be cleared before calling this
\r
411 * method. If this parse fails, the calendar may still
\r
412 * have been modified.
\r
414 * @param pos On input, the position at which to start parsing; on
\r
415 * output, the position at which parsing terminated, or the
\r
416 * start position if the parse failed.
\r
419 public void parse(String text, Calendar cal, ParsePosition pos) {
\r
420 Date result = dateFormat.parse(text, pos);
\r
421 cal.setTime(result);
\r
425 * Parse a date/time string according to the given parse position. For
\r
426 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
\r
427 * that is equivalent to Date(837039928046).
\r
429 * <p> By default, parsing is lenient: If the input is not in the form used
\r
430 * by this object's format method but can still be parsed as a date, then
\r
431 * the parse succeeds. Clients may insist on strict adherence to the
\r
432 * format by calling setLenient(false).
\r
434 * @see #setLenient(boolean)
\r
436 * @param text The date/time string to be parsed
\r
438 * @param pos On input, the position at which to start parsing; on
\r
439 * output, the position at which parsing terminated, or the
\r
440 * start position if the parse failed.
\r
442 * @return A Date, or null if the input could not be parsed
\r
445 public Date parse(String text, ParsePosition pos) {
\r
446 return dateFormat.parse(text, pos);
\r
450 * Parse a date/time string into an Object. This convenience method simply
\r
451 * calls parse(String, ParsePosition).
\r
453 * @see #parse(String, ParsePosition)
\r
456 public Object parseObject(String source, ParsePosition pos) {
\r
457 return parse(source, pos);
\r
461 * Constant for full style pattern.
\r
464 public static final int FULL = 0;
\r
467 * Constant for long style pattern.
\r
470 public static final int LONG = 1;
\r
473 * Constant for medium style pattern.
\r
476 public static final int MEDIUM = 2;
\r
479 * Constant for short style pattern.
\r
482 public static final int SHORT = 3;
\r
485 * Constant for default style pattern. Its value is MEDIUM.
\r
488 public static final int DEFAULT = MEDIUM;
\r
491 * Gets the time formatter with the default formatting style
\r
492 * for the default locale.
\r
493 * @return a time formatter.
\r
496 public final static DateFormat getTimeInstance() {
\r
497 return new DateFormat(java.text.DateFormat.getTimeInstance());
\r
501 * Gets the time formatter with the given formatting style
\r
502 * for the default locale.
\r
503 * @param style the given formatting style. For example,
\r
504 * SHORT for "h:mm a" in the US locale.
\r
505 * @return a time formatter.
\r
508 public final static DateFormat getTimeInstance(int style) {
\r
509 return new DateFormat(java.text.DateFormat.getTimeInstance(style));
\r
513 * Gets the time formatter with the given formatting style
\r
514 * for the given locale.
\r
515 * @param style the given formatting style. For example,
\r
516 * SHORT for "h:mm a" in the US locale.
\r
517 * @param aLocale the given locale.
\r
518 * @return a time formatter.
\r
521 public final static DateFormat getTimeInstance(int style, Locale aLocale) {
\r
522 return new DateFormat(java.text.DateFormat.getTimeInstance(style, aLocale));
\r
526 * Gets the time formatter with the given formatting style
\r
527 * for the given locale.
\r
528 * @param style the given formatting style. For example,
\r
529 * SHORT for "h:mm a" in the US locale.
\r
530 * @param aLocale the given locale.
\r
531 * @return a time formatter.
\r
534 public final static DateFormat getTimeInstance(int style, ULocale aLocale) {
\r
535 return new DateFormat(java.text.DateFormat.getTimeInstance(style, aLocale.toLocale()));
\r
539 * Gets the date formatter with the default formatting style
\r
540 * for the default locale.
\r
541 * @return a date formatter.
\r
544 public final static DateFormat getDateInstance() {
\r
545 return new DateFormat(java.text.DateFormat.getDateInstance());
\r
549 * Gets the date formatter with the given formatting style
\r
550 * for the default locale.
\r
551 * @param style the given formatting style. For example,
\r
552 * SHORT for "M/d/yy" in the US locale.
\r
553 * @return a date formatter.
\r
556 public final static DateFormat getDateInstance(int style) {
\r
557 return new DateFormat(java.text.DateFormat.getDateInstance(style));
\r
561 * Gets the date formatter with the given formatting style
\r
562 * for the given locale.
\r
563 * @param style the given formatting style. For example,
\r
564 * SHORT for "M/d/yy" in the US locale.
\r
565 * @param aLocale the given locale.
\r
566 * @return a date formatter.
\r
569 public final static DateFormat getDateInstance(int style, Locale aLocale) {
\r
570 return new DateFormat(java.text.DateFormat.getDateInstance(style, aLocale));
\r
574 * Gets the date formatter with the given formatting style
\r
575 * for the given locale.
\r
576 * @param style the given formatting style. For example,
\r
577 * SHORT for "M/d/yy" in the US locale.
\r
578 * @param aLocale the given locale.
\r
579 * @return a date formatter.
\r
580 * @stable ICU 3.4.3
\r
582 public final static DateFormat getDateInstance(int style, ULocale aLocale) {
\r
583 return new DateFormat(java.text.DateFormat.getDateInstance(style, aLocale.toLocale()));
\r
587 * Gets the date/time formatter with the default formatting style
\r
588 * for the default locale.
\r
589 * @return a date/time formatter.
\r
592 public final static DateFormat getDateTimeInstance() {
\r
593 return new DateFormat(java.text.DateFormat.getDateTimeInstance());
\r
597 * Gets the date/time formatter with the given date and time
\r
598 * formatting styles for the default locale.
\r
599 * @param dateStyle the given date formatting style. For example,
\r
600 * SHORT for "M/d/yy" in the US locale.
\r
601 * @param timeStyle the given time formatting style. For example,
\r
602 * SHORT for "h:mm a" in the US locale.
\r
603 * @return a date/time formatter.
\r
606 public final static DateFormat getDateTimeInstance(int dateStyle, int timeStyle) {
\r
607 return new DateFormat(java.text.DateFormat.getDateTimeInstance(dateStyle, timeStyle));
\r
611 * Gets the date/time formatter with the given formatting styles
\r
612 * for the given locale.
\r
613 * @param dateStyle the given date formatting style.
\r
614 * @param timeStyle the given time formatting style.
\r
615 * @param aLocale the given locale.
\r
616 * @return a date/time formatter.
\r
619 public final static DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale) {
\r
620 return new DateFormat(java.text.DateFormat.getDateTimeInstance(dateStyle, timeStyle, aLocale));
\r
624 * Gets the date/time formatter with the given formatting styles
\r
625 * for the given locale.
\r
626 * @param dateStyle the given date formatting style.
\r
627 * @param timeStyle the given time formatting style.
\r
628 * @param aLocale the given locale.
\r
629 * @return a date/time formatter.
\r
630 * @stable ICU 3.4.3
\r
632 public final static DateFormat getDateTimeInstance(int dateStyle, int timeStyle, ULocale aLocale) {
\r
633 return new DateFormat(java.text.DateFormat.getDateTimeInstance(dateStyle, timeStyle, aLocale.toLocale()));
\r
637 * Get a default date/time formatter that uses the SHORT style for both the
\r
638 * date and the time.
\r
641 public final static DateFormat getInstance() {
\r
642 return new DateFormat(java.text.DateFormat.getInstance());
\r
646 * Gets the set of locales for which DateFormats are installed.
\r
647 * @return the set of locales for which DateFormats are installed.
\r
650 public static Locale[] getAvailableLocales() {
\r
651 return java.text.DateFormat.getAvailableLocales();
\r
655 * Gets the set of locales for which DateFormats are installed.
\r
656 * @return the set of locales for which DateFormats are installed.
\r
657 * @stable ICU 3.4.3
\r
659 public static ULocale[] getAvailableULocales() {
\r
660 Locale[] locales = java.text.DateFormat.getAvailableLocales();
\r
661 ULocale[] ulocales = new ULocale[locales.length];
\r
662 for (int i = 0; i < locales.length; ++i) {
\r
663 ulocales[i] = ULocale.forLocale(locales[i]);
\r
669 * Set the calendar to be used by this date format. Initially, the default
\r
670 * calendar for the specified or default locale is used.
\r
671 * @param newCalendar the new Calendar to be used by the date format
\r
674 public void setCalendar(Calendar newCalendar) {
\r
675 dateFormat.setCalendar(newCalendar.calendar);
\r
679 * Gets the calendar associated with this date/time formatter.
\r
680 * @return the calendar associated with this date/time formatter.
\r
683 public Calendar getCalendar() {
\r
684 return new Calendar(dateFormat.getCalendar());
\r
688 * Allows you to set the number formatter.
\r
689 * @param newNumberFormat the given new NumberFormat.
\r
692 public void setNumberFormat(NumberFormat newNumberFormat) {
\r
693 dateFormat.setNumberFormat(newNumberFormat.numberFormat);
\r
697 * Gets the number formatter which this date/time formatter uses to
\r
698 * format and parse a time.
\r
699 * @return the number formatter which this date/time formatter uses.
\r
702 public NumberFormat getNumberFormat() {
\r
703 return new NumberFormat(dateFormat.getNumberFormat());
\r
707 * Sets the time zone for the calendar of this DateFormat object.
\r
708 * @param zone the given new time zone.
\r
711 public void setTimeZone(TimeZone zone) {
\r
712 dateFormat.setTimeZone(zone.timeZone);
\r
716 * Gets the time zone.
\r
717 * @return the time zone associated with the calendar of DateFormat.
\r
720 public TimeZone getTimeZone() {
\r
721 return new TimeZone(dateFormat.getTimeZone());
\r
725 * Specify whether or not date/time parsing is to be lenient. With
\r
726 * lenient parsing, the parser may use heuristics to interpret inputs that
\r
727 * do not precisely match this object's format. With strict parsing,
\r
728 * inputs must match this object's format.
\r
729 * @param lenient when true, parsing is lenient
\r
730 * @see com.ibm.icu.util.Calendar#setLenient
\r
733 public void setLenient(boolean lenient) {
\r
734 dateFormat.setLenient(lenient);
\r
738 * Tell whether date/time parsing is to be lenient.
\r
741 public boolean isLenient() {
\r
742 return dateFormat.isLenient();
\r
746 * Create a {@link DateFormat} object that can be used to format dates in
\r
747 * the calendar system specified by <code>cal</code>.
\r
749 * @param cal The calendar system for which a date format is desired.
\r
751 * @param dateStyle The type of date format desired. This can be
\r
752 * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM},
\r
755 * @param locale The locale for which the date format is desired.
\r
758 static final public DateFormat getDateInstance(Calendar cal, int dateStyle, Locale locale) {
\r
759 DateFormat df = getDateInstance(dateStyle, locale);
\r
760 df.setCalendar(cal);
\r
765 * Create a {@link DateFormat} object that can be used to format dates in
\r
766 * the calendar system specified by <code>cal</code>.
\r
768 * @param cal The calendar system for which a date format is desired.
\r
770 * @param dateStyle The type of date format desired. This can be
\r
771 * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM},
\r
774 * @param locale The locale for which the date format is desired.
\r
777 static final public DateFormat getDateInstance(Calendar cal, int dateStyle, ULocale locale) {
\r
778 DateFormat df = getDateInstance(dateStyle, locale);
\r
779 df.setCalendar(cal);
\r
784 * Create a {@link DateFormat} object that can be used to format times in
\r
785 * the calendar system specified by <code>cal</code>.
\r
787 * <b>Note:</b> When this functionality is moved into the core JDK, this method
\r
788 * will probably be replaced by a new overload of {@link DateFormat#getInstance}.
\r
790 * @param cal The calendar system for which a time format is desired.
\r
792 * @param timeStyle The type of time format desired. This can be
\r
793 * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM},
\r
796 * @param locale The locale for which the time format is desired.
\r
798 * @see DateFormat#getTimeInstance
\r
801 static final public DateFormat getTimeInstance(Calendar cal, int timeStyle, Locale locale) {
\r
802 DateFormat df = getTimeInstance(timeStyle, locale);
\r
803 df.setCalendar(cal);
\r
808 * Create a {@link DateFormat} object that can be used to format times in
\r
809 * the calendar system specified by <code>cal</code>.
\r
811 * <b>Note:</b> When this functionality is moved into the core JDK, this method
\r
812 * will probably be replaced by a new overload of {@link DateFormat#getInstance}.
\r
814 * @param cal The calendar system for which a time format is desired.
\r
816 * @param timeStyle The type of time format desired. This can be
\r
817 * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM},
\r
820 * @param locale The locale for which the time format is desired.
\r
822 * @see DateFormat#getTimeInstance
\r
825 static final public DateFormat getTimeInstance(Calendar cal, int timeStyle, ULocale locale) {
\r
826 DateFormat df = getTimeInstance(timeStyle, locale);
\r
827 df.setCalendar(cal);
\r
832 * Create a {@link DateFormat} object that can be used to format dates and times in
\r
833 * the calendar system specified by <code>cal</code>.
\r
835 * <b>Note:</b> When this functionality is moved into the core JDK, this method
\r
836 * will probably be replaced by a new overload of {@link DateFormat#getInstance}.
\r
838 * @param cal The calendar system for which a date/time format is desired.
\r
840 * @param dateStyle The type of date format desired. This can be
\r
841 * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM},
\r
844 * @param timeStyle The type of time format desired. This can be
\r
845 * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM},
\r
848 * @param locale The locale for which the date/time format is desired.
\r
850 * @see DateFormat#getDateTimeInstance
\r
853 static final public DateFormat getDateTimeInstance(Calendar cal, int dateStyle,
\r
854 int timeStyle, Locale locale) {
\r
855 DateFormat df = getDateTimeInstance(dateStyle, timeStyle, locale);
\r
856 df.setCalendar(cal);
\r
861 * Create a {@link DateFormat} object that can be used to format dates and times in
\r
862 * the calendar system specified by <code>cal</code>.
\r
864 * <b>Note:</b> When this functionality is moved into the core JDK, this method
\r
865 * will probably be replaced by a new overload of {@link DateFormat#getInstance}.
\r
867 * @param cal The calendar system for which a date/time format is desired.
\r
869 * @param dateStyle The type of date format desired. This can be
\r
870 * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM},
\r
873 * @param timeStyle The type of time format desired. This can be
\r
874 * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM},
\r
877 * @param locale The locale for which the date/time format is desired.
\r
879 * @see DateFormat#getDateTimeInstance
\r
882 static final public DateFormat getDateTimeInstance(Calendar cal, int dateStyle,
\r
883 int timeStyle, ULocale locale) {
\r
884 DateFormat df = getDateTimeInstance(dateStyle, timeStyle, locale);
\r
885 df.setCalendar(cal);
\r
890 * Convenience overload
\r
893 static final public DateFormat getInstance(Calendar cal, Locale locale) {
\r
894 return getDateTimeInstance(cal, MEDIUM, SHORT, locale);
\r
898 * Convenience overload
\r
901 public static final DateFormat getInstance(Calendar cal, ULocale locale) {
\r
902 return getDateTimeInstance(cal, MEDIUM, SHORT, locale);
\r
906 * Convenience overload
\r
909 public static final DateFormat getInstance(Calendar cal) {
\r
910 return getDateTimeInstance(cal, MEDIUM, SHORT, ULocale.getDefault());
\r
914 * Convenience overload
\r
917 public static final DateFormat getDateInstance(Calendar cal, int dateStyle) {
\r
918 DateFormat df = getDateInstance(dateStyle);
\r
919 df.setCalendar(cal);
\r
924 * Convenience overload
\r
927 static final public DateFormat getTimeInstance(Calendar cal, int timeStyle) {
\r
928 DateFormat df = getTimeInstance(timeStyle);
\r
929 df.setCalendar(cal);
\r
934 * Convenience overload
\r
937 static final public DateFormat getDateTimeInstance(Calendar cal, int dateStyle, int timeStyle) {
\r
938 DateFormat df = getDateTimeInstance(dateStyle, timeStyle);
\r
939 df.setCalendar(cal);
\r
944 * Return a string suitable for debugging.
\r
945 * @return a string suitable for debugging
\r
946 * @stable ICU 3.4.3
\r
948 public String toString() {
\r
949 return dateFormat.toString();
\r
953 * Return a clone of this DateFormat.
\r
954 * @return a clone of this DateFormat
\r
955 * @stable ICU 3.4.3
\r
957 public Object clone() {
\r
958 return new DateFormat((java.text.DateFormat)dateFormat.clone());
\r
962 * Return true if rhs is a DateFormatSymbols and has the same symbols as this.
\r
963 * @return true if rhs equals this
\r
964 * @stable ICU 3.4.3
\r
966 public boolean equals(Object arg0) {
\r
968 return dateFormat.equals(((DateFormat)arg0).dateFormat);
\r
970 catch (Exception e) {
\r
976 * Return a hashCode.
\r
977 * @return a hashCode
\r
978 * @stable ICU 3.4.3
\r
980 public int hashCode() {
\r
981 return dateFormat.hashCode();
\r