Classes for Formatting Dates
There are several classes for formatting dates. They are:
DateFormat: This is an abstract class, which formats and parses the dates and time in a language independent manner.
// this snippet formats the date//
String date = DateFormat.getDateTimeInstance (DateFormat.FULL,
DateFormat.SHORT, locale). format(new Date());
DateFormat.Field: This is a nested class that is used as attribute keys in the AttributedCharacterIterator. The
AttributedCharacterIterator allows iteration through both text and related attribute information. It is returned from
DateFormat.formatToCharacterIterator and is also used as field identifiers in FieldPosition.
DateFormatSymbols: It is a public class, which encapsulates localizable date-time formatting data, such a names of months days of week and the time zone data. Both
DateFormat class and
SimpleDateFormat class use DateFormatSymbols to encapsulate localizable date-time formatting data information.
DateFormatter: The DateFormatter class formats the date as per the format of the current locale.
SimpleDateFormat: The SimpleDateFormat is a class that formats and parses dates in a locale-sensitive manner.
//This snippet format the date as per the specified style//
SimpleDateFormat frmt = new SimpleDateFormat ("YYYY-MMM-DD", Locale.US);