![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e318. Formatting and Parsing a Time for a Locale Using Default FormatsEvery locale has four default formats for formatting and parsing times. They are calledSHORT , MEDIUM , LONG , and
FULL . The SHORT format consists entirely of numbers while
the FULL format contains most of the time components. There is
also a default format called DEFAULT and is the same as
MEDIUM .
Note: This example formats dates using the default locale
(which, in the author's case, is // Format Locale locale = Locale.ITALIAN; Date date = new Date(); String s = DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(date); // 22.33 s = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale).format(date); // 22.33.03 s = DateFormat.getTimeInstance(DateFormat.LONG, locale).format(date); // 22.33.03 PST s = DateFormat.getTimeInstance(DateFormat.FULL, locale).format(date); // 22.33.03 PST s = DateFormat.getTimeInstance(DateFormat.DEFAULT, locale).format(date); // 22.33.03 // Parse try { date = DateFormat.getTimeInstance( DateFormat.DEFAULT, locale).parse("22.33.03"); } catch (ParseException e) { }
e317. Parsing the Time Using a Custom Format e319. Formatting and Parsing a Time for a Locale
© 2002 Addison-Wesley. |