Top Description Inners Fields Constructors Methods
com.ibm.icu.text

public abstract Class DateFormat

extends UFormat
Class Inheritance
Known Direct Subclasses
com.ibm.icu.impl.RelativeDateFormat, com.ibm.icu.text.SimpleDateFormat
Imports
java.io.IOException, .InvalidObjectException, .ObjectInputStream, java.text.FieldPosition, .Format, .ParseException, .ParsePosition, java.util.Arrays, .Date, .EnumSet, .HashMap, .List, .Locale, .Map, .MissingResourceException, com.ibm.icu.impl.ICUResourceBundle, .RelativeDateFormat, com.ibm.icu.util.Calendar, .GregorianCalendar, .TimeZone, .ULocale, .ULocale.Category

ICU Enhancement

This class is ICU's replacement for java.text.DateFormat.

ICU

Methods, fields, and other functionality specific to ICU are labeled 'ICU'.

DateFormat is an abstract class for date/time formatting subclasses which formats and parses dates or time in a language-independent manner. The date/time formatting subclass, such as SimpleDateFormat, allows for formatting (i.e., date -> text), parsing (text -> date), and normalization. The date is represented as a Date object or as the milliseconds since January 1, 1970, 00:00:00 GMT.

DateFormat helps you to format and parse dates for any locale. Your code can be completely independent of the locale conventions for months, days of the week, or even the calendar format: lunar vs. solar. It provides many class methods for obtaining default date/time formatters based on the default for a given locale and a number of formatting styles or arbitrary "skeletons".

  1. The formatting styles include FULL, LONG, MEDIUM, and SHORT. More detail and examples of using these styles are provided in the method descriptions.
  2. The formatting styles only cover a fraction of the necessary usage. You often need to have just certain combinations of fields, like Month and Year, but have it to be formatted appropriate to a given locale. This is done using the (misnamed) getPatternInstance() method, supplying a skeleton. There are a number of constants that have common pre-defined skeletons, such as MINUTE_SECOND for something like "13:45" or YEAR_ABBR_MONTH for something like "Sept 2012".

To format a date for the current Locale, use one of the static factory methods:

myString = DateFormat.getDateInstance().format(myDate);
myString = DateFormat.getPatternInstance(DateFormat.YEAR_ABBR_MONTH).format(myDate);

If you are formatting multiple numbers, it is more efficient to get the format and use it multiple times so that the system doesn't have to fetch the information about the local language and country conventions multiple times.

DateFormat df = DateFormat.getDateInstance();
for (int i = 0; i < a.length; ++i) {
    output.println(df.format(myDate[i]) + "; ");
}

To format a date for a different Locale, specify it in the call to getDateInstance().

DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);

You can use a DateFormat to parse also.

myDate = df.parse(myString);

There are many static factory methods available. Use getDateInstance to get the normal date format for that country. Use getTimeInstance to get the time format for that country. Use getDateTimeInstance to get a date and time format. You can pass in different options to these factory methods to control the length of the result; from SHORT to MEDIUM to LONG to FULL. The exact result depends on the locale, but generally:

Use getPatternInstance to format with a skeleton. Typically this is with a predefined skeleton, like YEAR_ABBR_MONTH for something like "Sept 2012". If you don't want to use one of the predefined skeletons, you can supply your own. The skeletons are like the patterns in SimpleDateFormat, except they:

  1. only keep the field pattern letter and ignore all other parts in a pattern, such as space, punctuation, and string literals.
  2. are independent of the order of fields.
  3. ignore certain differences in the field's pattern letter length:
    1. For those non-digit calendar fields, the pattern letter length is important, such as MMM, MMMM, and MMMMM; E and EEEE, and the field's pattern letter length is honored.
    2. For the digit calendar fields, such as M or MM, d or dd, yy or yyyy, the field pattern length is ignored and the best match, which is defined in date time patterns, will be returned without honor the field pattern letter length in skeleton.

You can also set the time zone on the format if you wish. If you want even more control over the format or parsing, (or want to give your users more control), you can try casting the DateFormat you get from the factory methods to a SimpleDateFormat. This will work for the majority of countries; just remember to put it in a try block in case you encounter an unusual one.

You can also use forms of the parse and format methods with ParsePosition and FieldPosition to allow you to

Synchronization

Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.
Author
Mark Davis, Chen-Lieh Huang, Alan Liu
ICU Status
Stable since ICU 2.0.
See Also
UFormat, NumberFormat, SimpleDateFormat, com.ibm.icu.util.Calendar, com.ibm.icu.util.GregorianCalendar, com.ibm.icu.util.TimeZone

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
DateFormat.BooleanAttribute

boolean attributes

public static class
DateFormat.Field

The instances of this inner class are used as attribute keys and values in AttributedCharacterIterator that DateFormat.formatToCharacterIterator() method returns.

public static enum

Field Summary

Modifier and TypeField and Description
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final int
AM_PM_FIELD

FieldPosition selector for 'a' field alignment, corresponding to the Calendar#AM_PM field.

public static final int
private EnumSet<DateFormat.BooleanAttribute>
booleanAttributes

boolean attributes for this instance.

protected Calendar
calendar

The calendar that DateFormat uses to produce the time field values needed to implement date and time formatting.

private DisplayContext
pack-priv static final int
public static final int
DATE_FIELD

FieldPosition selector for 'd' field alignment, corresponding to the Calendar#DATE field.

public static final List<String>
DATE_SKELETONS

List of all of the date skeleton constants for iteration.

public static final String
DAY

ICU

public static final int
DAY_OF_WEEK_FIELD

FieldPosition selector for 'E' field alignment, corresponding to the Calendar#DAY_OF_WEEK field.

public static final int
DAY_OF_WEEK_IN_MONTH_FIELD

FieldPosition selector for 'F' field alignment, corresponding to the Calendar#DAY_OF_WEEK_IN_MONTH field.

public static final int
DAY_OF_YEAR_FIELD

FieldPosition selector for 'D' field alignment, corresponding to the Calendar#DAY_OF_YEAR field.

public static final int
DEFAULT

Constant for default style pattern.

public static final int
public static final int
ERA_FIELD

FieldPosition selector for 'G' field alignment, corresponding to the Calendar#ERA field.

public static final int
public static final int
public static final int
public static final int
public static final int
FULL

Constant for full style pattern.

public static final String
public static final String
HOUR

ICU

public static final int
HOUR0_FIELD

FieldPosition selector for 'K' field alignment, corresponding to the Calendar#HOUR field.

public static final int
HOUR1_FIELD

FieldPosition selector for 'h' field alignment, corresponding to the Calendar#HOUR field.

public static final String
HOUR24

ICU

public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final int
HOUR_OF_DAY0_FIELD

FieldPosition selector for 'H' field alignment, corresponding to the Calendar#HOUR_OF_DAY field.

public static final int
HOUR_OF_DAY1_FIELD

FieldPosition selector for 'k' field alignment, corresponding to the Calendar#HOUR_OF_DAY field.

public static final String
public static final String
JP_ERA_2019_JA

Constant for Unicode string name of new (in 2019) Japanese calendar era, Japanese abbreviated version (Han, or fullwidth Latin for testing).

public static final String
JP_ERA_2019_NARROW

Constant for Unicode string name of new (in 2019) Japanese calendar era, root and Japanese narrow version (ASCII-range characters).

public static final String
JP_ERA_2019_ROOT

Constant for Unicode string name of new (in 2019) Japanese calendar era, root/English abbreviated version (ASCII-range characters).

public static final int
public static final String
public static final int
LONG

Constant for long style pattern.

public static final int
MEDIUM

Constant for medium style pattern.

public static final int
MILLISECOND_FIELD

Alias for FRACTIONAL_SECOND_FIELD.

public static final int
public static final String
MINUTE

ICU

public static final int
MINUTE_FIELD

FieldPosition selector for 'm' field alignment, corresponding to the Calendar#MINUTE field.

public static final String
public static final String
MONTH

ICU

public static final String
public static final int
MONTH_FIELD

FieldPosition selector for 'M' field alignment, corresponding to the Calendar#MONTH field.

public static final String
public static final int
NONE

ICU

public static final String
public static final String
public static final String
protected NumberFormat
numberFormat

The number formatter that DateFormat uses to format numbers in dates and times.

public static final String
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final String
SECOND

ICU

public static final int
SECOND_FIELD

FieldPosition selector for 's' field alignment, corresponding to the Calendar#SECOND field.

private int
serialVersionOnStream

Describes the version of DateFormat present on the stream.

private static final long
public static final int
SHORT

Constant for short style pattern.

public static final String
public static final int
public static final String
public static final int
public static final int
public static final int
public static final List<String>
TIME_SKELETONS

List of all of the time skeleton constants for iteration.

public static final int
TIMEZONE_FIELD

FieldPosition selector for 'z' field alignment, corresponding to the Calendar#ZONE_OFFSET and Calendar#DST_OFFSET fields.

public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
WEEK_OF_MONTH_FIELD

FieldPosition selector for 'W' field alignment, corresponding to the Calendar#WEEK_OF_MONTH field.

public static final int
WEEK_OF_YEAR_FIELD

FieldPosition selector for 'w' field alignment, corresponding to the Calendar#WEEK_OF_YEAR field.

public static final String
public static final String
YEAR

ICU

public static final String
public static final String
public static final String
public static final String
public static final int
YEAR_FIELD

FieldPosition selector for 'y' field alignment, corresponding to the Calendar#YEAR field.

public static final String
public static final String
public static final String
public static final int
public static final String
public static final String
public static final String
public static final String
public static final int
public static final List<String>
ZONE_SKELETONS

List of all of the zone skeleton constants for iteration.

Constructor Summary

AccessConstructor and Description
protected
DateFormat()

Creates a new date format.

Method Summary

Modifier and TypeMethod and Description
public Object
clone()

Overrides java.text.Format.clone.

Overrides clone.
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Overrides equals.
pack-priv static void
public final StringBuffer

Returns:

the formatted time string.
format
(Object
must be a Number or a Date or a Calendar.
obj
,
StringBuffer
the string buffer for the returning time string.
toAppendTo
,
FieldPosition
keeps track of the position of the field within the returned string. On input: an alignment field, if desired. On output: the offsets of the alignment field. For example, given a time text "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition is DateFormat.YEAR_FIELD, the begin index and end index of fieldPosition will be set to 0 and 4, respectively. Notice that if the same time field appears more than once in a pattern, the fieldPosition will be set for the first occurrence of that time field. For instance, formatting a Date to the time string "1 PM PDT (Pacific Daylight Time)" using the pattern "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD, the begin index and end index of fieldPosition will be set to 5 and 8, respectively, for the first occurrence of the timezone pattern character 'z'.
fieldPosition
)

Implements abstract java.text.Format.format.

Formats a time object into a time string.
public abstract StringBuffer

Returns:

the formatted date/time string.
format
(Calendar
a Calendar set to the date and time to be formatted into a date/time string. When the calendar type is different from the internal calendar held by this DateFormat instance, the date and the time zone will be inherited from the input calendar, but other calendar field values will be calculated by the internal calendar.
cal
,
StringBuffer
the string buffer for the returning date/time string.
toAppendTo
,
FieldPosition
keeps track of the position of the field within the returned string. On input: an alignment field, if desired. On output: the offsets of the alignment field. For example, given a time text "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition is DateFormat.YEAR_FIELD, the begin index and end index of fieldPosition will be set to 0 and 4, respectively. Notice that if the same time field appears more than once in a pattern, the fieldPosition will be set for the first occurrence of that time field. For instance, formatting a Date to the time string "1 PM PDT (Pacific Daylight Time)" using the pattern "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD, the begin index and end index of fieldPosition will be set to 5 and 8, respectively, for the first occurrence of the timezone pattern character 'z'.
fieldPosition
)

Formats a date into a date/time string.

public StringBuffer

Returns:

the formatted date/time string.
format
(Date
a Date to be formatted into a date/time string.
date
,
StringBuffer
the string buffer for the returning date/time string.
toAppendTo
,
FieldPosition
keeps track of the position of the field within the returned string. On input: an alignment field, if desired. On output: the offsets of the alignment field. For example, given a time text "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition is DateFormat.YEAR_FIELD, the begin index and end index of fieldPosition will be set to 0 and 4, respectively. Notice that if the same time field appears more than once in a pattern, the fieldPosition will be set for the first occurrence of that time field. For instance, formatting a Date to the time string "1 PM PDT (Pacific Daylight Time)" using the pattern "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD, the begin index and end index of fieldPosition will be set to 5 and 8, respectively, for the first occurrence of the timezone pattern character 'z'.
fieldPosition
)

Formats a Date into a date/time string.

public final String

Returns:

the formatted time string.
format
(Date
the time value to be formatted into a time string.
date
)

Formats a Date into a date/time string.

private static DateFormat
get(int
a value from 0 to 3 indicating the time format, or -1 to indicate no date
dateStyle
,
int
a value from 0 to 3 indicating the time format, or -1 to indicate no time
timeStyle
,
ULocale
the locale for the format
loc
,
Calendar
the calendar to be used, or null
cal
)

Creates a DateFormat with the given time and/or date style in the given locale.

public static Locale[]

Returns:

the set of locales for which DateFormats are installed.
getAvailableLocales
()

Returns the set of locales for which DateFormats are installed.

public static ULocale[]

Returns:

the set of locales for which DateFormats are installed.
getAvailableULocales
()

ICU

public boolean
getBooleanAttribute(DateFormat.BooleanAttribute key)

Returns the current value for the specified BooleanAttribute for this instance if attribute is missing false is returned.

public Calendar

Returns:

the calendar associated with this date/time formatter.
getCalendar
()

Returns the calendar associated with this date/time formatter.

public DisplayContext

Returns:

the current DisplayContext setting for the specified type
getContext
(DisplayContext.Type
the DisplayContext.Type whose value to return
type
)

ICU

public static final DateFormat

Returns:

a date formatter.
getDateInstance
()

Returns the date formatter with the default formatting style for the default FORMAT locale.

public static final DateFormat

Returns:

a date formatter.
getDateInstance
(int
the given formatting style. For example, SHORT for "M/d/yy" in the US locale. As currently implemented, relative date formatting only affects a limited range of calendar days before or after the current date, based on the CLDR <field type="day">/<relative> data: For example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range, relative dates are formatted using the corresponding non-relative style.
style
)

Returns the date formatter with the given formatting style for the default FORMAT locale.

public static final DateFormat

Returns:

a date formatter.
getDateInstance
(int
the given formatting style. For example, SHORT for "M/d/yy" in the US locale. As currently implemented, relative date formatting only affects a limited range of calendar days before or after the current date, based on the CLDR <field type="day">/<relative> data: For example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range, relative dates are formatted using the corresponding non-relative style.
style
,
Locale
the given locale.
aLocale
)

Returns the date formatter with the given formatting style for the given locale.

public static final DateFormat

Returns:

a date formatter.
getDateInstance
(int
the given formatting style. For example, SHORT for "M/d/yy" in the US locale. As currently implemented, relative date formatting only affects a limited range of calendar days before or after the current date, based on the CLDR <field type="day">/<relative> data: For example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range, relative dates are formatted using the corresponding non-relative style.
style
,
ULocale
the given ulocale.
locale
)

Returns the date formatter with the given formatting style for the given locale.

public static final DateFormat
getDateInstance(Calendar
The calendar system for which a date format is desired.
cal
,
int
The type of date format desired. This can be DateFormat#SHORT, DateFormat#MEDIUM, etc.
dateStyle
,
Locale
The locale for which the date format is desired.
locale
)

Creates a DateFormat object that can be used to format dates in the calendar system specified by cal.

public static final DateFormat
getDateInstance(Calendar
The calendar system for which a date format is desired.
cal
,
int
The type of date format desired. This can be DateFormat#SHORT, DateFormat#MEDIUM, etc.
dateStyle
,
ULocale
The locale for which the date format is desired.
locale
)

Creates a DateFormat object that can be used to format dates in the calendar system specified by cal.

public static final DateFormat
getDateInstance(Calendar
The calendar system for which a date format is desired.
cal
,
int
The type of date format desired. This can be DateFormat#SHORT, DateFormat#MEDIUM, etc.
dateStyle
)

Creates a DateFormat object for the default locale that can be used to format dates in the calendar system specified by cal.

public static final DateFormat

Returns:

a date/time formatter.
getDateTimeInstance
()

Returns the date/time formatter with the default formatting style for the default FORMAT locale.

public static final DateFormat

Returns:

a date/time formatter.
getDateTimeInstance
(int
the given date formatting style. For example, SHORT for "M/d/yy" in the US locale. As currently implemented, relative date formatting only affects a limited range of calendar days before or after the current date, based on the CLDR <field type="day">/<relative> data: For example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range, relative dates are formatted using the corresponding non-relative style.
dateStyle
,
int
the given time formatting style. For example, SHORT for "h:mm a" in the US locale. Relative time styles are not currently supported, and behave just like the corresponding non-relative style.
timeStyle
)

Returns the date/time formatter with the given date and time formatting styles for the default FORMAT locale.

public static final DateFormat

Returns:

a date/time formatter.
getDateTimeInstance
(int
the given date formatting style. As currently implemented, relative date formatting only affects a limited range of calendar days before or after the current date, based on the CLDR <field type="day">/<relative> data: For example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range, relative dates are formatted using the corresponding non-relative style.
dateStyle
,
int
the given time formatting style. Relative time styles are not currently supported, and behave just like the corresponding non-relative style.
timeStyle
,
Locale
the given locale.
aLocale
)

Returns the date/time formatter with the given formatting styles for the given locale.

public static final DateFormat

Returns:

a date/time formatter.
getDateTimeInstance
(int
the given date formatting style. As currently implemented, relative date formatting only affects a limited range of calendar days before or after the current date, based on the CLDR <field type="day">/<relative> data: For example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range, relative dates are formatted using the corresponding non-relative style.
dateStyle
,
int
the given time formatting style. Relative time styles are not currently supported, and behave just like the corresponding non-relative style.
timeStyle
,
ULocale
the given ulocale.
locale
)

Returns the date/time formatter with the given formatting styles for the given locale.

public static final DateFormat
getDateTimeInstance(Calendar
The calendar system for which a date/time format is desired.
cal
,
int
The type of date format desired. This can be DateFormat#SHORT, DateFormat#MEDIUM, etc.
dateStyle
,
int
The type of time format desired. This can be DateFormat#SHORT, DateFormat#MEDIUM, etc.
timeStyle
,
Locale
The locale for which the date/time format is desired.
locale
)

Creates a DateFormat object that can be used to format dates and times in the calendar system specified by cal.

public static final DateFormat
getDateTimeInstance(Calendar
The calendar system for which a date/time format is desired.
cal
,
int
The type of date format desired. This can be DateFormat#SHORT, DateFormat#MEDIUM, etc.
dateStyle
,
int
The type of time format desired. This can be DateFormat#SHORT, DateFormat#MEDIUM, etc.
timeStyle
,
ULocale
The locale for which the date/time format is desired.
locale
)

Creates a DateFormat object that can be used to format dates and times in the calendar system specified by cal.

public static final DateFormat
getDateTimeInstance(Calendar
The calendar system for which a date/time format is desired.
cal
,
int
The type of date format desired. This can be DateFormat#SHORT, DateFormat#MEDIUM, etc.
dateStyle
,
int
The type of time format desired. This can be DateFormat#SHORT, DateFormat#MEDIUM, etc.
timeStyle
)

Creates a DateFormat object for the default locale that can be used to format dates and times in the calendar system specified by cal.

public static final DateFormat
getInstance()

Returns a default date/time formatter that uses the SHORT style for both the date and the time.

public static final DateFormat
getInstance(Calendar
The calendar system for which a date/time format is desired.
cal
,
Locale
The locale for which the date/time format is desired.
locale
)

Returns a date/time formatter that uses the SHORT style for both the date and the time.

public static final DateFormat
getInstance(Calendar
The calendar system for which a date/time format is desired.
cal
,
ULocale
The locale for which the date/time format is desired.
locale
)

Returns a date/time formatter that uses the SHORT style for both the date and the time.

public static final DateFormat
getInstance(Calendar
The calendar system for which a date/time format is desired.
cal
)

Returns a default date/time formatter that uses the SHORT style for both the date and the time.

public static final DateFormat
getInstanceForSkeleton(String
The skeleton that selects the fields to be formatted. (Uses the DateTimePatternGenerator.) This can be DateFormat#ABBR_MONTH, DateFormat#MONTH_WEEKDAY_DAY, etc.
skeleton
)

ICU

public static final DateFormat
getInstanceForSkeleton(String
The skeleton that selects the fields to be formatted. (Uses the DateTimePatternGenerator.) This can be DateFormat#ABBR_MONTH, DateFormat#MONTH_WEEKDAY_DAY, etc.
skeleton
,
Locale
The locale for which the date/time format is desired.
locale
)

ICU

public static final DateFormat
getInstanceForSkeleton(String
The skeleton that selects the fields to be formatted. (Uses the DateTimePatternGenerator.) This can be DateFormat#ABBR_MONTH, DateFormat#MONTH_WEEKDAY_DAY, etc.
skeleton
,
ULocale
The locale for which the date/time format is desired.
locale
)

ICU

public static final DateFormat
getInstanceForSkeleton(Calendar
The calendar system for which a date/time format is desired.
cal
,
String
The skeleton that selects the fields to be formatted. (Uses the DateTimePatternGenerator.) This can be DateFormat#ABBR_MONTH, DateFormat#MONTH_WEEKDAY_DAY, etc.
skeleton
,
Locale
The locale for which the date/time format is desired.
locale
)

ICU

public static final DateFormat
getInstanceForSkeleton(Calendar
The calendar system for which a date/time format is desired.
cal
,
String
The skeleton that selects the fields to be formatted. (Uses the DateTimePatternGenerator.) This can be DateFormat#ABBR_MONTH, DateFormat#MONTH_WEEKDAY_DAY, etc.
skeleton
,
ULocale
The locale for which the date/time format is desired.
locale
)

ICU

public NumberFormat

Returns:

the number formatter which this date/time formatter uses.
getNumberFormat
()

Returns the number formatter which this date/time formatter uses to format and parse a time.

public static final DateFormat
getPatternInstance(String
The skeleton that selects the fields to be formatted. (Uses the DateTimePatternGenerator.) This can be DateFormat#ABBR_MONTH, DateFormat#MONTH_WEEKDAY_DAY, etc.
skeleton
)

ICU

public static final DateFormat
getPatternInstance(String
The skeleton that selects the fields to be formatted. (Uses the DateTimePatternGenerator.) This can be DateFormat#ABBR_MONTH, DateFormat#MONTH_WEEKDAY_DAY, etc.
skeleton
,
Locale
The locale for which the date/time format is desired.
locale
)

ICU

public static final DateFormat
getPatternInstance(String
The skeleton that selects the fields to be formatted. (Uses the DateTimePatternGenerator.) This can be DateFormat#ABBR_MONTH, DateFormat#MONTH_WEEKDAY_DAY, etc.
skeleton
,
ULocale
The locale for which the date/time format is desired.
locale
)

ICU

public static final DateFormat
getPatternInstance(Calendar
The calendar system for which a date/time format is desired.
cal
,
String
The skeleton that selects the fields to be formatted. (Uses the DateTimePatternGenerator.) This can be DateFormat#ABBR_MONTH, DateFormat#MONTH_WEEKDAY_DAY, etc.
skeleton
,
Locale
The locale for which the date/time format is desired.
locale
)

ICU

public static final DateFormat
getPatternInstance(Calendar
The calendar system for which a date/time format is desired.
cal
,
String
The skeleton that selects the fields to be formatted. (Uses the DateTimePatternGenerator.) This can be DateFormat#ABBR_MONTH, DateFormat#MONTH_WEEKDAY_DAY, etc.
skeleton
,
ULocale
The locale for which the date/time format is desired.
locale
)

ICU

public static final DateFormat

Returns:

a time formatter.
getTimeInstance
()

Gets the time formatter with the default formatting style for the default FORMAT locale.

public static final DateFormat

Returns:

a time formatter.
getTimeInstance
(int
the given formatting style. For example, SHORT for "h:mm a" in the US locale. Relative time styles are not currently supported, and behave just like the corresponding non-relative style.
style
)

Returns the time formatter with the given formatting style for the default FORMAT locale.

public static final DateFormat

Returns:

a time formatter.
getTimeInstance
(int
the given formatting style. For example, SHORT for "h:mm a" in the US locale. Relative time styles are not currently supported, and behave just like the corresponding non-relative style.
style
,
Locale
the given locale.
aLocale
)

Returns the time formatter with the given formatting style for the given locale.

public static final DateFormat

Returns:

a time formatter.
getTimeInstance
(int
the given formatting style. For example, SHORT for "h:mm a" in the US locale. Relative time styles are not currently supported, and behave just like the corresponding non-relative style.
style
,
ULocale
the given ulocale.
locale
)

Returns the time formatter with the given formatting style for the given locale.

public static final DateFormat
getTimeInstance(Calendar
The calendar system for which a time format is desired.
cal
,
int
The type of time format desired. This can be DateFormat#SHORT, DateFormat#MEDIUM, etc.
timeStyle
,
Locale
The locale for which the time format is desired.
locale
)

Creates a DateFormat object that can be used to format times in the calendar system specified by cal.

public static final DateFormat
getTimeInstance(Calendar
The calendar system for which a time format is desired.
cal
,
int
The type of time format desired. This can be DateFormat#SHORT, DateFormat#MEDIUM, etc.
timeStyle
,
ULocale
The locale for which the time format is desired.
locale
)

Creates a DateFormat object that can be used to format times in the calendar system specified by cal.

public static final DateFormat
getTimeInstance(Calendar
The calendar system for which a time format is desired.
cal
,
int
The type of time format desired. This can be DateFormat#SHORT, DateFormat#MEDIUM, etc.
timeStyle
)

Creates a DateFormat object that can be used to format times in the calendar system specified by cal.

public TimeZone

Returns:

the time zone associated with the calendar of DateFormat.
getTimeZone
()

Returns the time zone.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Overrides hashCode.
public boolean
isCalendarLenient()

Returns whether date/time parsing in the encapsulated Calendar object is lenient.

public boolean
isLenient()

Returns whether both date/time parsing in the encapsulated Calendar object and DateFormat whitespace & numeric processing is lenient.

public Date

Returns:

A Date, or null if the input could not be parsed
parse
(String
The date/time string to be parsed
text
)

Parses a date/time string.

public abstract void
parse(String
The date/time string to be parsed
text
,
Calendar
The calendar set on input to the date and time to be used for missing values in the date/time string being parsed, and set on output to the parsed date/time. In general, this should be initialized before calling this method - either cleared or set to the current date, depending on desired behavior. If this parse fails, the calendar may still have been modified. When the calendar type is different from the internal calendar held by this DateFormat instance, calendar field values will be parsed based on the internal calendar initialized with the time and the time zone taken from this calendar, then the parse result (time in milliseconds and time zone) will be set back to this calendar.
cal
,
ParsePosition
On input, the position at which to start parsing; on output, the position at which parsing terminated, or the start position if the parse failed.
pos
)

Parses a date/time string according to the given parse position.

public Date

Returns:

A Date, or null if the input could not be parsed
parse
(String
The date/time string to be parsed
text
,
ParsePosition
On input, the position at which to start parsing; on output, the position at which parsing terminated, or the start position if the parse failed.
pos
)

Parses a date/time string according to the given parse position.

public Object
parseObject(String
A String, part of which should be parsed.
source
,
ParsePosition
A ParsePosition object with index and error index information as described above.
pos
)

Implements abstract java.text.Format.parseObject.

Parses a date/time string into an Object.
private void
readObject(ObjectInputStream stream)

First, read in the default serializable data.

public DateFormat
setBooleanAttribute(DateFormat.BooleanAttribute key, boolean value)

Sets a boolean attribute for this instance.

public void
setCalendar(Calendar
the new Calendar to be used by the date format
newCalendar
)

Sets the calendar to be used by this date format.

public void
setCalendarLenient(boolean
when true, Calendar parsing is lenient
lenient
)

Specifies whether date/time parsing in the encapsulated Calendar object should be lenient.

public void
setContext(DisplayContext
The DisplayContext value to set.
context
)

ICU

public void
setLenient(boolean
True specifies date/time interpretation to be lenient.
lenient
)

Specifies whether date/time parsing is to be lenient.

public void
setNumberFormat(NumberFormat
the given new NumberFormat.
newNumberFormat
)

Sets the number formatter.

public void
setTimeZone(TimeZone
the given new time zone.
zone
)

Sets the time zone for the calendar of this DateFormat object.

Inherited from com.ibm.icu.text.UFormat:
getLocalesetLocale