XSD Tutorial – XSD Date and Time

XSD Tutorial covers topics on XSD Data Types, XSD Date, XSD Empty, XSD Text , XSD Mixed, XSD Indicators, XSD Substitution ,XSD Examples, XSD Numeric, XSD Elements .

Lets discuss the XSD Date and Time <xs:date> Data Types in detail

The XSD Date <xs:date> data type depicts the Date and Time format in the XML Document.

<xs:date> format

The <xs:date> format (YYYY-MM-DD) in the XML Document depicts

  • YYYY depicts the Year
  • MM depicts the Month
  • DD depicts the Date

<xs:date> example

The below example depicts the data representation in Date format in the XML document

<xs:element name=”createdDate” type =”xs:date” />

Output : <createdDate>2020-05-07</createdDate>

XSD Date TimeZone

The TimeZone values can be handled in the date by applying the below formats

  • Converting the Date with TimeZone , the date can be appended with “Z” for UTC TimeZone like <createdDate>2020-05-07Z</createdDate>
  • Converting the Date with TimeZone, the data can be appended with Positive or negative time like

<createdDate>2020-05-07-04:00</createdDate> // reduces 4 hours from current system time

<createdDate>2020-05-07+04:00</createdDate> // increases 4 hours from current system time

<xs:time> data type

<xs:time> data type depicts the time in the format hh:mm:ss where

  • hh depicts the hour
  • mm depicts the minute
  • ss depicts the second

<xs:time> example:

<xs:element name=”creationTime” type =”xs:time”/>

<creationTime>05:07:21</creationTime>

<xs:datetime> data type

<xs:date> data type depicts the date format (YYYY-MM-DD)

<xs:time> data type depicts the time format (hh:mm:ss)

<xs:datetime> data type depicts the date and time format together (YYYY-MM-DDThh:mm:ss) where

  • YYYY depicts the Year
  • MM depicts the Month
  • DD depicts the Date
  • T depicts the start of the Time vlaue
  • hh depicts the hour
  • mm depicts the minute
  • ss depicts the second

<xs:element name=”creationDateTime” type =”xs:datetime”/>

<creationDateTime>2020-05-07T05:07:21</creationDateTime>

<xs:duration> data type

<xs:duration> depicts the time interval using ” PnYnMnDTnHnMnS ” format where

  • P depicts the period (required)
  • nY depicts the number of years
  • nM depicts the number of months
  • nD depicts the number of days
  • T depicts the start of a time vlaue
  • nH depicts the number of hours
  • nM depicts the number of minutes
  • nS depicts the number of seconds

<xs:duration> example

<xs:duration>P1Y</xs:duration> // depicts period of 1 year

<xs:duration>P1Y2M</xs:duration> // depicts period of 1 year 2 month

<xs:duration>P1Y2M3D</xs:duration> // depicts period of 1 year 2 month 3 Days