Class DateTime

java.lang.Object
org.exolab.castor.types.DateTimeBase
org.exolab.castor.types.DateTime
All Implemented Interfaces:
Serializable, Cloneable

public class DateTime extends DateTimeBase
Describe an XML schema DateTime.

The format is defined by W3C XML Schema Recommendation and ISO8601 i.e (-)CCYY-MM-DD'T'HH:MM:SS(.SSSSS)(Z|(+|-)hh:mm)

Version:
$Revision: 0000 $
Author:
Edward Kuns
See Also:
  • Constructor Details

    • DateTime

      public DateTime()
      Default constructor.
    • DateTime

      public DateTime(short[] values)
      Constructs a XML Schema DateTime instance given all the values of the different date and time (but not time zone) fields.

      By default a DateTime is not UTC, and is local. To set a timezone, you need to separately call DateTimeBase.setZone(short, short).

      Parameters:
      values - an array of shorts that represent the different fields of Time.
      See Also:
    • DateTime

      public DateTime(long dateAsLong)
      Creates a new XML Schema DateTime instance from a long that represents a Date. No time zone information is set.

      By default a DateTime is not UTC, and is local. To set a timezone, you need to separately call DateTimeBase.setZone(short, short).

      Parameters:
      dateAsLong - java.util.Date represented as a long.
    • DateTime

      public DateTime(Date dateRef)
      Creates a new XML Schema DateTime instance from a java.util.Date. No time zone information is set.

      By default a DateTime is not UTC, and is local. To set a timezone, you need to separately call DateTimeBase.setZone(short, short).

      Parameters:
      dateRef - a java.util.Date to convert.
    • DateTime

      public DateTime(String date) throws ParseException
      Constructs a DateTime from a String. The String is expected to be in W3C Schema DateTime format.
      Parameters:
      date - the string representing the date
      Throws:
      ParseException - if we are passed an illegal value
  • Method Details

    • setValues

      public void setValues(short[] values)
      Sets all the fields to the values provided in an Array. The Array must be at least eight entries long. Extra entries are ignored. The order of entries in the array is as follows:
      • century
      • year
      • month
      • day
      • hour
      • minute
      • second
      • millisecond
      If a Time Zone is to be specified, it has to be set separately by using setZone. A time zone previously set will not be cleared.
      Specified by:
      setValues in class DateTimeBase
      Parameters:
      values - An array of shorts containing the values for the DateTime
    • getValues

      public short[] getValues()
      Returns an array of shorts with all the fields that describe this DateTime type. The order of entries in the array is as follows:
      • century
      • year
      • month
      • day
      • hour
      • minute
      • second
      • millisecond
      Note:the time zone is not included.
      Specified by:
      getValues in class DateTimeBase
      Returns:
      an array of short with all the fields that describe this Date type.
    • toDate

      public Date toDate()
      Converts this DateTime into a local java.util.Date.
      Specified by:
      toDate in class DateTimeBase
      Returns:
      a local java.util.Date representing this DateTime.
    • toLong

      public long toLong()
      Converts this DateTime into a long value representing a java.util.Date.
      Returns:
      This DateTime instance as a long value representing a java.util.Date.
    • toString

      public String toString()
      Converts this DateTime to a string. The format is defined by W3C XML Schema recommendation and ISO8601: (+|-)CCYY-MM-DDTHH:MM:SS.SSS(+/-)HH:SS
      Overrides:
      toString in class Object
      Returns:
      a string representing this Date
    • parse

      public static DateTime parse(String str) throws ParseException
      Parses a String into a new DateTime instance.
      Parameters:
      str - the string to parse
      Returns:
      a new DateTime instance with the value of the parsed string.
      Throws:
      ParseException - If the string to parse does not follow the right format
    • parseDateTime

      public static DateTime parseDateTime(String str) throws ParseException
      Parses a String into a new DateTime instance.
      Parameters:
      str - the string to parse
      Returns:
      a new DateTime instance with the value of the parsed string.
      Throws:
      ParseException - If the string to parse does not follow the right format