public class DateFormatUtils extends Object
Date and time formatting utilities and constants.
Formatting is performed using the thread-safe
FastDateFormat class.
Note that the JDK has a bug wherein calling Calendar.get(int) will override any previously called Calendar.clear() calls. See LANG-755.
| Modifier and Type | Field and Description |
|---|---|
static FastDateFormat |
ISO_DATE_FORMAT
ISO 8601 formatter for date without time zone.
|
static FastDateFormat |
ISO_DATE_TIME_ZONE_FORMAT
ISO 8601-like formatter for date with time zone.
|
static FastDateFormat |
ISO_DATETIME_FORMAT
ISO 8601 formatter for date-time without time zone.
|
static FastDateFormat |
ISO_DATETIME_TIME_ZONE_FORMAT
ISO 8601 formatter for date-time with time zone.
|
static FastDateFormat |
ISO_TIME_FORMAT
ISO 8601 formatter for time without time zone.
|
static FastDateFormat |
ISO_TIME_NO_T_FORMAT
ISO 8601-like formatter for time without time zone.
|
static FastDateFormat |
ISO_TIME_NO_T_TIME_ZONE_FORMAT
ISO 8601-like formatter for time with time zone.
|
static FastDateFormat |
ISO_TIME_TIME_ZONE_FORMAT
ISO 8601 formatter for time with time zone.
|
static FastDateFormat |
SMTP_DATETIME_FORMAT
SMTP (and probably other) date headers.
|
| Constructor and Description |
|---|
DateFormatUtils()
DateFormatUtils instances should NOT be constructed in standard programming.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
format(Calendar calendar,
String pattern)
Formats a calendar into a specific pattern.
|
static String |
format(Calendar calendar,
String pattern,
Locale locale)
Formats a calendar into a specific pattern in a locale.
|
static String |
format(Calendar calendar,
String pattern,
TimeZone timeZone)
Formats a calendar into a specific pattern in a time zone.
|
static String |
format(Calendar calendar,
String pattern,
TimeZone timeZone,
Locale locale)
Formats a calendar into a specific pattern in a time zone and locale.
|
static String |
format(Date date,
String pattern)
Formats a date/time into a specific pattern.
|
static String |
format(Date date,
String pattern,
Locale locale)
Formats a date/time into a specific pattern in a locale.
|
static String |
format(Date date,
String pattern,
TimeZone timeZone)
Formats a date/time into a specific pattern in a time zone.
|
static String |
format(Date date,
String pattern,
TimeZone timeZone,
Locale locale)
Formats a date/time into a specific pattern in a time zone and locale.
|
static String |
format(long millis,
String pattern)
Formats a date/time into a specific pattern.
|
static String |
format(long millis,
String pattern,
Locale locale)
Formats a date/time into a specific pattern in a locale.
|
static String |
format(long millis,
String pattern,
TimeZone timeZone)
Formats a date/time into a specific pattern in a time zone.
|
static String |
format(long millis,
String pattern,
TimeZone timeZone,
Locale locale)
Formats a date/time into a specific pattern in a time zone and locale.
|
static String |
formatUTC(Date date,
String pattern)
Formats a date/time into a specific pattern using the UTC time zone.
|
static String |
formatUTC(Date date,
String pattern,
Locale locale)
Formats a date/time into a specific pattern using the UTC time zone.
|
static String |
formatUTC(long millis,
String pattern)
Formats a date/time into a specific pattern using the UTC time zone.
|
static String |
formatUTC(long millis,
String pattern,
Locale locale)
Formats a date/time into a specific pattern using the UTC time zone.
|
public static final FastDateFormat ISO_DATETIME_FORMAT
yyyy-MM-dd'T'HH:mm:ss.public static final FastDateFormat ISO_DATETIME_TIME_ZONE_FORMAT
yyyy-MM-dd'T'HH:mm:ssZZ.public static final FastDateFormat ISO_DATE_FORMAT
yyyy-MM-dd.public static final FastDateFormat ISO_DATE_TIME_ZONE_FORMAT
yyyy-MM-ddZZ.
This pattern does not comply with the formal ISO 8601 specification
as the standard does not allow a time zone without a time.public static final FastDateFormat ISO_TIME_FORMAT
'T'HH:mm:ss.public static final FastDateFormat ISO_TIME_TIME_ZONE_FORMAT
'T'HH:mm:ssZZ.public static final FastDateFormat ISO_TIME_NO_T_FORMAT
HH:mm:ss.
This pattern does not comply with the formal ISO 8601 specification
as the standard requires the 'T' prefix for times.public static final FastDateFormat ISO_TIME_NO_T_TIME_ZONE_FORMAT
HH:mm:ssZZ.
This pattern does not comply with the formal ISO 8601 specification
as the standard requires the 'T' prefix for times.public static final FastDateFormat SMTP_DATETIME_FORMAT
EEE, dd MMM yyyy HH:mm:ss Z in US locale.public DateFormatUtils()
DateFormatUtils instances should NOT be constructed in standard programming.
This constructor is public to permit tools that require a JavaBean instance to operate.
public static String formatUTC(long millis, String pattern)
Formats a date/time into a specific pattern using the UTC time zone.
millis - the date to format expressed in millisecondspattern - the pattern to use to format the date, not nullpublic static String formatUTC(Date date, String pattern)
Formats a date/time into a specific pattern using the UTC time zone.
date - the date to format, not nullpattern - the pattern to use to format the date, not nullpublic static String formatUTC(long millis, String pattern, Locale locale)
Formats a date/time into a specific pattern using the UTC time zone.
millis - the date to format expressed in millisecondspattern - the pattern to use to format the date, not nulllocale - the locale to use, may be nullpublic static String formatUTC(Date date, String pattern, Locale locale)
Formats a date/time into a specific pattern using the UTC time zone.
date - the date to format, not nullpattern - the pattern to use to format the date, not nulllocale - the locale to use, may be nullpublic static String format(long millis, String pattern)
Formats a date/time into a specific pattern.
millis - the date to format expressed in millisecondspattern - the pattern to use to format the date, not nullpublic static String format(Date date, String pattern)
Formats a date/time into a specific pattern.
date - the date to format, not nullpattern - the pattern to use to format the date, not nullpublic static String format(Calendar calendar, String pattern)
Formats a calendar into a specific pattern.
calendar - the calendar to format, not nullpattern - the pattern to use to format the calendar, not nullFastDateFormat.format(Calendar)public static String format(long millis, String pattern, TimeZone timeZone)
Formats a date/time into a specific pattern in a time zone.
millis - the time expressed in millisecondspattern - the pattern to use to format the date, not nulltimeZone - the time zone to use, may be nullpublic static String format(Date date, String pattern, TimeZone timeZone)
Formats a date/time into a specific pattern in a time zone.
date - the date to format, not nullpattern - the pattern to use to format the date, not nulltimeZone - the time zone to use, may be nullpublic static String format(Calendar calendar, String pattern, TimeZone timeZone)
Formats a calendar into a specific pattern in a time zone.
calendar - the calendar to format, not nullpattern - the pattern to use to format the calendar, not nulltimeZone - the time zone to use, may be nullFastDateFormat.format(Calendar)public static String format(long millis, String pattern, Locale locale)
Formats a date/time into a specific pattern in a locale.
millis - the date to format expressed in millisecondspattern - the pattern to use to format the date, not nulllocale - the locale to use, may be nullpublic static String format(Date date, String pattern, Locale locale)
Formats a date/time into a specific pattern in a locale.
date - the date to format, not nullpattern - the pattern to use to format the date, not nulllocale - the locale to use, may be nullpublic static String format(Calendar calendar, String pattern, Locale locale)
Formats a calendar into a specific pattern in a locale.
calendar - the calendar to format, not nullpattern - the pattern to use to format the calendar, not nulllocale - the locale to use, may be nullFastDateFormat.format(Calendar)public static String format(long millis, String pattern, TimeZone timeZone, Locale locale)
Formats a date/time into a specific pattern in a time zone and locale.
millis - the date to format expressed in millisecondspattern - the pattern to use to format the date, not nulltimeZone - the time zone to use, may be nulllocale - the locale to use, may be nullpublic static String format(Date date, String pattern, TimeZone timeZone, Locale locale)
Formats a date/time into a specific pattern in a time zone and locale.
date - the date to format, not nullpattern - the pattern to use to format the date, not null, not nulltimeZone - the time zone to use, may be nulllocale - the locale to use, may be nullpublic static String format(Calendar calendar, String pattern, TimeZone timeZone, Locale locale)
Formats a calendar into a specific pattern in a time zone and locale.
calendar - the calendar to format, not nullpattern - the pattern to use to format the calendar, not nulltimeZone - the time zone to use, may be nulllocale - the locale to use, may be nullFastDateFormat.format(Calendar)Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.