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.
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
DEFAULT specify this style. Similarly, the
getTimeInstance( ) methods return a
DateFormat object that formats and parses times,
getDateTimeInstance( ) methods return a
DateFormat object that formats both dates and
times. These methods also optionally take a format style constant and
) returns a default
that formats both dates and times in the
Once you have created a
DateFormat object, you can use the
setCalendar( ) and
) methods if you want to format the date using a calendar
or time zone other than the default. The various
) methods convert
to strings using whatever format is encapsulated in the
DateFormat object. The
parseObject( ) methods perform the reverse
operation; they parse a string formatted according to the rules of
DateFormat object and convert it into to a
Date object. The
SHORT constants ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.