Package org.exolab.castor.types
Class DateTime
- java.lang.Object
-
- org.exolab.castor.types.DateTimeBase
-
- 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
Constructors Constructor Description DateTime()
Default constructor.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.DateTime(java.util.Date dateRef)
Creates a new XML Schema DateTime instance from a java.util.Date.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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
-
-
-
-
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:- century
- year
- month
- day
- hour
- minute
- second
- millisecond
setZone
. A time zone previously set will not be cleared.- Specified by:
setValues
in classDateTimeBase
- 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
- Specified by:
getValues
in classDateTimeBase
- 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 classDateTimeBase
- 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 classjava.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
-
-