public class DateFormat extends Object
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static CharSequence |
format(long date) |
Formats the date text based on the default format of the current
Locale. |
static CharSequence |
format(long date,
CharSequence format) |
Formats the date text in the specified format and the current
Locale. |
static CharSequence |
format(long date,
CharSequence format,
String locale) |
Formats the date text in the specified format and
locale. |
static CharSequence |
format(String date,
CharSequence format,
String parseFormat) |
Formats the specified date text in the given format and the current
Locale. |
static CharSequence |
format(String date,
CharSequence format,
String parseFormat,
String locale) |
Formats the specified date text in the given format and
locale. |
public static CharSequence format(long date)
Locale.
For example, if the current Locale is US, the formatted string is similar to the following:
"Thursday, April 22, 2021 at 3:45:01 PM Central Standard Time".date - Indicates the number of milliseconds elapsed since the Unix epoch (00:00:00 UTC on January 1, 1970).public static CharSequence format(long date, CharSequence format)
Locale.
In the specified format, the keyword y indicates the year, M indicates the month,
and d indicates the day.
You can also add text in '' format, for example, 'Today'.
For details about the format keywords that can be entered, see the UDateFormatField keyword at
the ICU website:date - Indicates the number of milliseconds elapsed since the Unix epoch (00:00:00 UTC on January 1, 1970).format - Indicates the format to be specified.format is null, the date text will be formatted in the default format of the
current java.util.LocaleLocale.public static CharSequence format(long date, CharSequence format, String locale)
locale.
In the specified format, the keyword y indicates the year, M indicates the month, and
d indicates the day.
You can also add text in '' format, for example, 'Today'.
For details about the format keywords that can be entered, see the UDateFormatField keyword at the
ICU website:date - Indicates the number of milliseconds elapsed since the Unix epoch (00:00:00 UTC on January 1, 1970).format - Indicates the format to be specified.locale - Indicates the Locale to be specified. The value must be a valid character string
representing Locale, for example, "en_US", or null.locale is null, the current java.util.LocaleLocale will be used.
If format is null, the date text will be formatted in the default format of the specified
locale.public static CharSequence format(String date, CharSequence format, String parseFormat)
Locale.
This method cannot automatically identify the date format of the specified date string.
You must use the parseFormat parameter to declare the date format.
In the specified format, the keyword y indicates the year, M indicates the month,
and d indicates the day.
You can also add text in '' format, for example, 'Today'.
For details about the format keywords that can be entered, see the UDateFormatField keyword at
the ICU website:date - Indicates the date string to be formatted.format - Indicates the format to be specified.parseFormat - Indicates the format in which the date string is to be parsed.
For example, if the specified date text is "20210405", the parseFormat value is
"yyyyMMdd".null, date will be returned without formatting.public static CharSequence format(String date, CharSequence format, String parseFormat, String locale)
locale.
This method cannot automatically identify the date format of the specified date string. You must use
the parseFormat parameter to declare the date format.
In the specified format, the keyword y indicates the year, M indicates the month, and d
indicates the day.
You can also add text in '' format, for example, 'Today'.
For details about the format keywords that can be entered, see the UDateFormatField keyword at the ICU
website:date - Indicates the date string to be formatted.format - Indicates the format to be specified.parseFormat - Indicates the format in which the date string is to be parsed.
For example, if the specified date text is "20210405", the parseFormat value is
"yyyyMMdd".locale - Indicates the Locale to be specified. The value must be a valid character string
representing Locale, for example, "en_US", or null.locale is null, the current java.util.LocaleLocale will be used.
If any input parameter except locale is set to null, date will be returned without
formatting.