Java Reference
In-Depth Information
Static Method
Description
getTimeInstance()
Returns a time formatter for the default locale that uses the
default style for the time.
getTimeInstance
(int timeStyle)
Returns a time formatter for the default locale that uses the
style for the time that is specified by the argument.
getTimeInstance
(int style,
Locale aLocale)
Returns a time formatter for the locale specified by the
second argument that uses the style for the time that is
specified by the first argument.
getDateInstance()
Returns a date formatter for the default locale that uses the
default style for the date.
getDateInstance
(int dateStyle)
Returns a date formatter for the default locale that uses the
style for the date specified by the argument.
getDateInstance
(int dateStyle,
Locale aLocale)
Returns a date formatter for the locale specified by the
second argument that uses the style for the date that is
specified by the first argument.
getInstance()
Returns a default date and time formatter that uses the
SHORT style for both the date and the time.
getDateTimeInstance()
Returns a date and time formatter for the default locale that
uses the default style for both the date and the time.
getDateTimeInstance
(int dateStyle,
int timeStyle)
Returns a date and time formatter for the current locale that
uses the styles for the date and the time specified by the
arguments.
getDateTimeInstance
(int dateStyle,
int timeStyle,
Locale aLocale)
Returns a date and time formatter for aLocale with the
styles for the date and the time as specified by the first two
arguments.
When you've obtained a DateFormat object for the country and the style that you want, and the sort
of data you want to format - the date or the time or both - you're ready to produce a String from the
Date object.
All you need to do is to pass the Date object to the format() method for the DateFormat object.
For example:
Date today = new Date(); // Object for now - today's date
DateFormat fmt = getDateTimeInstance(DateFormat.FULL, DataFormat.FULL, Locale.US);
String formatted = fmt.format(today);
After executing these statements, the String variable, formatted , will contain a full representation of
the date and the time when the Date object, today , was created.
We can try out some dates and formats in a simple example.
Search WWH ::




Custom Search