Class XMLSchemaDateTimeParser
java.lang.Object
XMLSchemaDateTimeParser
public class XMLSchemaDateTimeParser
- extends Object
Lightweight parser for XMLSchema dateTime.
Calendar
calendar = XMLSchemaDateTimeParser.parse
("2005-11-14T02:16:38Z");
- Author:
- Takahiko Kawasaki
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
XMLSchemaDateTimeParser
public XMLSchemaDateTimeParser()
parse
public static Calendar parse(String dateTime)
- Parse XMLSchema dateTime.
XMLSchema dateTime
is a subset of ISO 8601
and its format can be described as follows.
'-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? ('Z' | ('+' | '-') hh ':' mm)?
Below are examples.
- 2005-11-14T02:16:38Z
- 2005-11-14T02:16:38-09:00
- 2005-11-14T02:16:38.125
Note that this parser additionally imposes some restrictions on the date time
format as described below. However, practically speaking, these are trivial.
- The specification allows the year part to be a 5-or-more-digit number, but
this parser assumes only 4-digit number at the year part.
- The specification allows a leading hyphen ('-') to indicate B.C. years, but
this parser just ignores the negative sign.
- The specification does not mention the length of the millisecond part, but
this parser assumes that the length is in between 1 and 3.
- Parameters:
dateTime
- A string in the XMLSchema dateTime format. Leading and trailing white spaces,
if the given argument has any, are ignored.
- Returns:
- A
Calendar
instance that represents the given date time.
If the given argument is null or the format of the string does not
comply with the XMLSchema dateTime format, null is returned.