Name
DateFormat
Synopsis
This class formats and parses
dates and times in a locale-specific
way. As an abstract class, it cannot be instantiated directly, but it
provides a number of static methods that return instances of a
concrete subclass you can use to format dates in a variety of ways.
The getDateInstance( ) methods return a
DateFormat object suitable for formatting dates in
either the default locale or a specified locale. A formatting style
may also optionally be specified; the constants
FULL, LONG,
MEDIUM, SHORT, and
DEFAULT specify this style. Similarly, the
getTimeInstance( ) methods return a
DateFormat object that formats and parses times,
and the getDateTimeInstance( ) methods return a
DateFormat object that formats both dates and
times. These methods also optionally take a format style constant and
a Locale. Finally, getInstance(
) returns a default DateFormat object
that formats both dates and times in the SHORT
format.
Once you have created a
DateFormat object, you can use the
setCalendar( ) and setTimeZone(
) methods if you want to format the date using a calendar
or time zone other than the default. The various format(
) methods convert java.util.Date objects
to strings using whatever format is encapsulated in the
DateFormat object. The parse( )
and parseObject( ) methods perform the reverse
operation; they parse a string formatted according to the rules of
the DateFormat object and convert it into to a
Date object. The DEFAULT,
FULL, MEDIUM,
LONG, and SHORT constants ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access