Class XMLSchemaDateTimeParser

java.lang.Object
  extended by XMLSchemaDateTimeParser

public class XMLSchemaDateTimeParser
extends Object

Lightweight parser for XMLSchema dateTime.


 Calendar calendar = XMLSchemaDateTimeParser.parse("2005-11-14T02:16:38Z");
 

Author:
Takahiko Kawasaki

Constructor Summary
XMLSchemaDateTimeParser()
           
 
Method Summary
static Calendar parse(String dateTime)
          Parse XMLSchema dateTime.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLSchemaDateTimeParser

public XMLSchemaDateTimeParser()
Method Detail

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.

Note that this parser additionally imposes some restrictions on the date time format as described below. However, practically speaking, these are trivial.

  1. 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.
  2. The specification allows a leading hyphen ('-') to indicate B.C. years, but this parser just ignores the negative sign.
  3. 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.