org.exolab.castor.types
Class DateTime

java.lang.Object
  extended by org.exolab.castor.types.DateTimeBase
      extended by org.exolab.castor.types.DateTime
All Implemented Interfaces:
java.io.Serializable, java.lang.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:
Serialized Form

Field Summary
 
Fields inherited from class org.exolab.castor.types.DateTimeBase
EQUALS, GREATER_THAN, INDETERMINATE, LESS_THAN, MAX_TIME_ZONE_COMPARISON_OFFSET, WRONGLY_PLACED
 
Constructor Summary
DateTime()
          Default constructor.
DateTime(java.util.Date dateRef)
          Creates a new XML Schema DateTime instance from a java.util.Date.
DateTime(long dateAsLong)
          Creates a new XML Schema DateTime instance from a long that represents a Date.
DateTime(short[] values)
          Constructs a XML Schema DateTime instance given all the values of the different date and time (but not time zone) fields.
DateTime(java.lang.String date)
          Constructs a DateTime from a String.
 
Method Summary
 short[] getValues()
          Returns an array of shorts with all the fields that describe this DateTime type.
static DateTime parse(java.lang.String str)
          Parses a String into a new DateTime instance.
static DateTime parseDateTime(java.lang.String str)
          Parses a String into a new DateTime instance.
 void setValues(short[] values)
          Sets all the fields to the values provided in an Array.
 java.util.Date toDate()
          Converts this DateTime into a local java.util.Date.
 long toLong()
          Converts this DateTime into a long value representing a java.util.Date.
 java.lang.String toString()
          Converts this DateTime to a string.
 
Methods inherited from class org.exolab.castor.types.DateTimeBase
addDuration, appendDateString, appendTimeString, appendTimeZoneString, clone, compareTo, equal, equals, getCentury, getDay, getHour, getMilli, getMinute, getMonth, getSeconds, getYear, getZoneHour, getZoneMinute, hasCentury, hasDay, hashCode, hasHour, hasIsNegative, hasMilli, hasMinute, hasMonth, hasSeconds, hasYear, isLeap, isNegative, isUTC, isZoneNegative, normalize, parseDay, parseMonth, parseTime, parseTimeZone, parseYear, setCentury, setDateFormatTimeZone, setDateFormatTimeZone, setDay, setHour, setMilliSecond, setMinute, setMonth, setNegative, setSecond, setSecond, setUTC, setYear, setZone, setZoneHour, setZoneMinute, setZoneNegative, toCalendar
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

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:
setValues(short[])

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(java.util.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(java.lang.String date)
         throws java.text.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:
java.text.ParseException - if we are passed an illegal value
Method Detail

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: 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: 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 java.util.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 java.lang.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 java.lang.Object
Returns:
a string representing this Date

parse

public static DateTime parse(java.lang.String str)
                      throws java.text.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:
java.text.ParseException - If the string to parse does not follow the right format

parseDateTime

public static DateTime parseDateTime(java.lang.String str)
                              throws java.text.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:
java.text.ParseException - If the string to parse does not follow the right format


Copyright © 2011. All Rights Reserved.