Package cz.jiripinkas.jsitemapgenerator
Class W3CDateFormat
- java.lang.Object
-
- java.text.Format
-
- java.text.DateFormat
-
- java.text.SimpleDateFormat
-
- cz.jiripinkas.jsitemapgenerator.W3CDateFormat
-
- All Implemented Interfaces:
Serializable
,Cloneable
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:
- YEAR: YYYY (eg 1997)
- MONTH: YYYY-MM (eg 1997-07)
- DAY: YYYY-MM-DD (eg 1997-07-16)
- MINUTE: YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
- SECOND: YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
- MILLISECOND: YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
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:
- If the date has fractional milliseconds (e.g. 2009-06-06T19:49:04.45Z) we'll use the MILLISECOND pattern
- Otherwise, if the date has non-zero seconds (e.g. 2009-06-06T19:49:04Z) we'll use the SECOND pattern
- Otherwise, if the date is not at exactly midnight (e.g. 2009-06-06T19:49Z) we'll use the MINUTE pattern
- Otherwise, we'll use the DAY pattern. If you want to format using the MONTH or YEAR pattern, you must declare it explicitly.
DateFormat.setTimeZone(TimeZone)
method.- Author:
- Dan Fabulich
- See Also:
- Date and Time Formats, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
W3CDateFormat.Pattern
The six patterns defined by W3C, plusW3CDateFormat.Pattern.AUTO
configuration-
Nested classes/interfaces inherited from class java.text.DateFormat
DateFormat.Field
-
-
Field Summary
Fields Modifier and Type Field Description static TimeZone
ZULU
The GMT ("zulu") time zone, for your convenience-
Fields inherited from class java.text.DateFormat
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 Summary
Constructors Constructor Description W3CDateFormat()
Build a formatter in AUTO modeW3CDateFormat(W3CDateFormat.Pattern pattern)
Build a formatter using the specified Pattern, or AUTO mode
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringBuffer
format(Date date, StringBuffer toAppendTo, FieldPosition pos)
This is what you override when you extend DateFormat; useDateFormat.format(Date)
insteadDate
parse(String text, ParsePosition pos)
This is what you override when you extend DateFormat; useDateFormat.parse(String)
instead-
Methods inherited from class java.text.SimpleDateFormat
applyLocalizedPattern, applyPattern, clone, equals, formatToCharacterIterator, get2DigitYearStart, getDateFormatSymbols, hashCode, set2DigitYearStart, setDateFormatSymbols, toLocalizedPattern, toPattern
-
Methods inherited from class java.text.DateFormat
format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, isLenient, parse, parseObject, setCalendar, setLenient, setNumberFormat, setTimeZone
-
Methods inherited from class java.text.Format
format, parseObject
-
-
-
-
Field Detail
-
ZULU
public static final TimeZone ZULU
The GMT ("zulu") time zone, for your convenience
-
-
Constructor Detail
-
W3CDateFormat
public W3CDateFormat()
Build a formatter in AUTO mode
-
W3CDateFormat
public W3CDateFormat(W3CDateFormat.Pattern pattern)
Build a formatter using the specified Pattern, or AUTO mode- Parameters:
pattern
- pattern
-
-
Method Detail
-
format
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition pos)
This is what you override when you extend DateFormat; useDateFormat.format(Date)
instead- Overrides:
format
in classSimpleDateFormat
-
parse
public Date parse(String text, ParsePosition pos)
This is what you override when you extend DateFormat; useDateFormat.parse(String)
instead- Overrides:
parse
in classSimpleDateFormat
-
-