Java Reference
In-Depth Information
Exercise 24.3 : Write a program that takes a string argument that is
parsed into the date to print, and print that date in all possible styles.
How lenient will the date parsing be?
24.5.1. Using Formatter with Dates and Times
The java.util.Formatter class, described in Chapter 22 , also supports the
formatting of date and time information using a supplied Date or Calen-
dar object, or a date represented as a long (or Long ). Using the avail-
able format conversions you can extract information about that date/
time, including things like the day of the month, the day of the week,
the year, the hour of the day, and so forth.
The output of the formatter is localized according to the locale associ-
ated with that formatter, so things like the name of the day and month
will be in the correct languagehowever, digits themselves are not local-
ized. Unlike DateFormat , a formatter cannot help you with localization is-
sues such as knowing whether the month or the day should come first in
a dateit simply provides access to each individual component and your
program must combine them in the right way.
A date/time conversion is indicated by a format conversion of t (or T for
uppercase output), followed by various suffixes that indicate what is to
be output and in what form. The following table lists the conversion suf-
fixes related to times:
Hour of the day for 24-hour clock format. Two digits: 0023
H
Hour of the day for 12-hour clock format. Two digits: 0112
I
Hour of the day for 24-hour clock format: 023
k
 
Search WWH ::




Custom Search