public class W3CDateFormat extends SimpleDateFormat
Formats and parses dates in the six defined W3C date time formats. These formats are described in "Date and Time Formats", http://www.w3.org/TR/NOTE-datetime.
The formats are:
Note that W3C timezone designators (TZD) are either the letter "Z" (for GMT) or a pattern like "+00:30" or "-08:00". This is unlike RFC 822 timezones generated by SimpleDateFormat, which omit the ":" like this: "+0030" or "-0800".
This class allows you to either specify which format pattern to use, or (by default) to automatically guess which pattern to use (AUTO mode). When parsing in AUTO mode, we'll try parsing using each pattern until we find one that works. When formatting in AUTO mode, we'll use this algorithm:
DateFormat.setTimeZone(TimeZone)
method.Modifier and Type | Class and Description |
---|---|
static class |
W3CDateFormat.Pattern
The six patterns defined by W3C, plus
W3CDateFormat.Pattern.AUTO configuration |
DateFormat.Field
Modifier and Type | Field and Description |
---|---|
static TimeZone |
ZULU
The GMT ("zulu") time zone, for your convenience
|
AM_PM_FIELD, calendar, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, numberFormat, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD
Constructor and Description |
---|
W3CDateFormat()
Build a formatter in AUTO mode
|
W3CDateFormat(W3CDateFormat.Pattern pattern)
Build a formatter using the specified Pattern, or AUTO mode
|
Modifier and Type | Method and Description |
---|---|
StringBuffer |
format(Date date,
StringBuffer toAppendTo,
FieldPosition pos)
This is what you override when you extend DateFormat; use
DateFormat.format(Date) instead |
Date |
parse(String text,
ParsePosition pos)
This is what you override when you extend DateFormat; use
DateFormat.parse(String) instead |
applyLocalizedPattern, applyPattern, clone, equals, formatToCharacterIterator, get2DigitYearStart, getDateFormatSymbols, hashCode, set2DigitYearStart, setDateFormatSymbols, toLocalizedPattern, toPattern
format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, isLenient, parse, parseObject, setCalendar, setLenient, setNumberFormat, setTimeZone
format, parseObject
public static final TimeZone ZULU
public W3CDateFormat()
public W3CDateFormat(W3CDateFormat.Pattern pattern)
pattern
- patternpublic StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition pos)
DateFormat.format(Date)
insteadformat
in class SimpleDateFormat
public Date parse(String text, ParsePosition pos)
DateFormat.parse(String)
insteadparse
in class SimpleDateFormat
Copyright © 2015. All rights reserved.