The Apache Software Foundation > Apache XMLBeans
 

DateTime Sample

Description

Author: Rashmi Banthia

Available: 2004-10-28

Versions: xmlbeans-1.0.3, xmlbeans-v2

This sample demonstrates how you can work with XML Schema primitive types date, dateTime, time, duration, gDay.
This sample illustrates how you can

  1. Convert org.apache.xmlbeans.XmlDate to java.util.Calendar,org.apache.xmlbeans.GDate, java.util.Date
  2. Convert org.apache.xmlbeans.XmlTime to java.util.Calendar,org.apache.xmlbeans.GDate, java.util.Date
  3. Convert org.apache.xmlbeans.XmlDuration to org.apache.xmlbeans.GDuration
  4. Convert org.apache.xmlbeans.XmlGday to java.util.Calendar,org.apache.xmlbeans.GDate, Day - primitive java int
  5. Get/Set XML Schema primitive types date, dateTime, time, duration, and gDay.

XMLBean Types provide mapping between natural Java classes and W3C Schema types. For eg:

Schema Type Formal Class Natural Java Class
xs:date XmlDate java.util.Calendar (XmlCalendar)
xs:time XmlTime java.util.Calendar (XmlCalendar)
xs:dateTime XmlDateTime java.util.Calendar (XmlCalendar)
xs:duration XmlDuration org.apache.xmlbeans.GDuration

The XmlCalendar is a subclass of GregorianCalendar that modifies several key details in the behavior of GregorianCalendar to make it more useful when dealing with XML dates.

Files