< prev index next >

src/java.base/share/classes/java/text/DateFormat.java

Print this page
rev 47733 : 8176841: Additional Unicode Language-Tag Extensions
8189134: New system properties for the default Locale extensions
Reviewed-by:


  80  * </blockquote>
  81  * <p>If you are formatting multiple dates, it is
  82  * more efficient to get the format and use it multiple times so that
  83  * the system doesn't have to fetch the information about the local
  84  * language and country conventions multiple times.
  85  * <blockquote>
  86  * <pre>{@code
  87  * DateFormat df = DateFormat.getDateInstance();
  88  * for (int i = 0; i < myDate.length; ++i) {
  89  *     output.println(df.format(myDate[i]) + "; ");
  90  * }
  91  * }</pre>
  92  * </blockquote>
  93  * <p>To format a date for a different Locale, specify it in the
  94  * call to {@link #getDateInstance(int, Locale) getDateInstance()}.
  95  * <blockquote>
  96  * <pre>{@code
  97  * DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);
  98  * }</pre>
  99  * </blockquote>







 100  * <p>You can use a DateFormat to parse also.
 101  * <blockquote>
 102  * <pre>{@code
 103  * myDate = df.parse(myString);
 104  * }</pre>
 105  * </blockquote>
 106  * <p>Use {@code getDateInstance} to get the normal date format for that country.
 107  * There are other static factory methods available.
 108  * Use {@code getTimeInstance} to get the time format for that country.
 109  * Use {@code getDateTimeInstance} to get a date and time format. You can pass in
 110  * different options to these factory methods to control the length of the
 111  * result; from {@link #SHORT} to {@link #MEDIUM} to {@link #LONG} to {@link #FULL}. The exact result depends
 112  * on the locale, but generally:
 113  * <ul><li>{@link #SHORT} is completely numeric, such as {@code 12.13.52} or {@code 3:30pm}
 114  * <li>{@link #MEDIUM} is longer, such as {@code Jan 12, 1952}
 115  * <li>{@link #LONG} is longer, such as {@code January 12, 1952} or {@code 3:30:32pm}
 116  * <li>{@link #FULL} is pretty completely specified, such as
 117  * {@code Tuesday, April 12, 1952 AD or 3:30:42pm PST}.
 118  * </ul>
 119  *




  80  * </blockquote>
  81  * <p>If you are formatting multiple dates, it is
  82  * more efficient to get the format and use it multiple times so that
  83  * the system doesn't have to fetch the information about the local
  84  * language and country conventions multiple times.
  85  * <blockquote>
  86  * <pre>{@code
  87  * DateFormat df = DateFormat.getDateInstance();
  88  * for (int i = 0; i < myDate.length; ++i) {
  89  *     output.println(df.format(myDate[i]) + "; ");
  90  * }
  91  * }</pre>
  92  * </blockquote>
  93  * <p>To format a date for a different Locale, specify it in the
  94  * call to {@link #getDateInstance(int, Locale) getDateInstance()}.
  95  * <blockquote>
  96  * <pre>{@code
  97  * DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);
  98  * }</pre>
  99  * </blockquote>
 100  *
 101  * <p>If the specified locale contains "ca" (calendar), "rg" (region override),
 102  * and/or "tz" (timezone) <a href="../util/Locale.html#def_locale_extension">Unicode
 103  * extensions</a>, the calendar, the country and/or the time zone for formatting
 104  * are overriden. If both "ca" and "rg" are specified, the calendar from "ca"
 105  * extension supersedes the implicit one from "rg" extension.
 106  *
 107  * <p>You can use a DateFormat to parse also.
 108  * <blockquote>
 109  * <pre>{@code
 110  * myDate = df.parse(myString);
 111  * }</pre>
 112  * </blockquote>
 113  * <p>Use {@code getDateInstance} to get the normal date format for that country.
 114  * There are other static factory methods available.
 115  * Use {@code getTimeInstance} to get the time format for that country.
 116  * Use {@code getDateTimeInstance} to get a date and time format. You can pass in
 117  * different options to these factory methods to control the length of the
 118  * result; from {@link #SHORT} to {@link #MEDIUM} to {@link #LONG} to {@link #FULL}. The exact result depends
 119  * on the locale, but generally:
 120  * <ul><li>{@link #SHORT} is completely numeric, such as {@code 12.13.52} or {@code 3:30pm}
 121  * <li>{@link #MEDIUM} is longer, such as {@code Jan 12, 1952}
 122  * <li>{@link #LONG} is longer, such as {@code January 12, 1952} or {@code 3:30:32pm}
 123  * <li>{@link #FULL} is pretty completely specified, such as
 124  * {@code Tuesday, April 12, 1952 AD or 3:30:42pm PST}.
 125  * </ul>
 126  *


< prev index next >