Object
Cloneable
, Comparable
, Serializable
This class provides the Java binding for the XML schema type timeInstant as specified in Section 3.2.24 of XML Schema Part 2: Datatypes.
timeInstant represents a specific instant of a time. The value space of timeInstant is the space of combinations of date and time of day values as defined in ISO 8601.
Time zone specification is not optional.
Example: 2001-01-18T09:00:00.0005Z
.
In this representation, one can represent arbitrary precision
seconds. Timezone offsets can be represented with the optional zone
indicator Z
for UTC or one of -hh::mm
or
+hh:mm
to indicate the difference from UTC.
Instances of this type can be constructed from valid instances of timeInstant strings, java.util.Date, java.sql.Date, and java.util.Timestamp.
As the XML Schema specification allows arbitrary precision
seconds representation, this class preserves the precision of
seconds when instances of this class are created from a timeInstant
string. However, such precision may be lost when instances of
java.util.Date, java.sql.Date or java.sql.Timestamp are obtained
from an instance of TimeInstant
.
long
and
double
respectively in the Java programming
language.java.util.Date
, java.sql.Date
and
java.sql.Timestamp
) can not represent values of
years beyond the range of -2147483648 to 2147483647, this class
chooses a higher precision for these values. The same applies to
seconds. Therefore, any conversion between instances of
TimeDuration
and instances of
java.util.Date
, java.sql.Date
and
java.sql.Timestamp
may be subjected rounding and
loss of information. Design Note: Although a timeInstant is a derived type (derived from recurringDuration), there is no inheritance association between TimeInstant and TimeDuration. From the point of XML Schema, a recurringDuration is a more general type, and all the derived types (including timeInstant, time, timePeriod, recurringDate, and recurringDay) can be created by restricting the values facets of recurringDuration. For instance, a timeInstant can be created by restricting both the duration and period facets to be P0Y.
However, in this design, the same notion is not applied to the corresponding Java types. This is to prevent extraneous methods appearing on classes for derived types. For instance, by not having a specialization association between TimeInstant and RecurringDuration, this design prevents methods such as getDuration() from the TimeInstant class. The design instead relies on delegation.
Object
TimeInstant
Cloneable
, Comparable
, Serializable
Constructor Summary |
|
Method Summary |
public |
|
public int |
|
public int | |
public int | |
public int | |
public static |
|
public static |
|
public static |
|
public static |
|
public static |
|
public static |
|
public static |
|
public static |
|
public boolean | |
public |
|
public int |
|
public long |
|
public int |
|
public int |
|
public int |
|
public int |
|
public int |
|
public int |
|
public double |
|
public int |
|
public double |
|
public |
|
public long |
|
public int |
|
public int |
|
public boolean |
|
public |
|
public void |
|
public void |
|
public void |
|
public void |
|
public void |
|
public void |
|
public void |
|
public void |
|
public void |
|
public void |
|
public void |
|
public void |
|
public void |
|
public void |
|
public |
|
public | |
public |
|
public |
|
public |
|
public |
|
public |
|
Methods from class java.lang. |
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods from interface java.lang. |
compareTo |
Constructor Detail |
protected TimeInstant()
Method Detail |
public Object
clone()
Returns a copy of this TimeInstant. Actually clones the original Calendar object for
the new TimeInstant so the original won't be modified.
Object.clone()
public int compareTo(TimeInstant
anotherTimeInstant)
Compares this TimeInstant to another TimeInstant object
(represented in the same time zone) in their canonical
representation. Two time instances are considered to be equal
if individual fields of the representation
(<+/->CCYY:MM:DDThh:mm:ss.sss
public int compareTo(Date
date)
Compares this TimeInstant to a Date object in their canonical
representation. A Date and a TimeInstant are considered to be equal
if individual fields of the representation
(<+/->CCYY:MM:DDThh:mm:ss.sss
public int compareTo(Time
time)
Compares this TimeInstant to a Time object in their canonical
representation. A Time and a TimeInstant are considered to be equal
if individual fields of the representation
(hh:mm:ss.sss
public int compareTo(Object
anotherObject)
Compares this TimeInstant with another object. If the other
object is a TimeInstant, this method behaves like
compareTo(TimeInstant). If the other object is a Time, this
method behaves like compareTo(Time). If the other object is a
Date, this method behaves like compareTo(Date). Otherwise,
it throws a ClassCastException.
public static TimeInstant
createTimeInstant()
Returns a TimeInstant instance for the current
time at the local time zone.
public staticGiven a string, returns a TimeInstant instance.TimeInstant
createTimeInstant(String
timeInstant)
throwsParseException
ParseException
public staticGiven a java.util.Date, returns a TimeInstant instance.TimeInstant
createTimeInstant(Date
date)
public staticGiven a java.sql.Date, returns a TimeInstant instance.TimeInstant
createTimeInstant(Date
date)
public staticGiven a java.util.Timestamp, returns a TimeInstant instance.TimeInstant
createTimeInstant(Timestamp
timestamp)
public staticGiven a java.util.Calendar, returns a TimeInstant instance.TimeInstant
createTimeInstant(Calendar
c)
public static TimeInstant
createTimeInstant(double time)
Given the value of milliseconds since January 1, 1970, 00:00:00
GMT, returns a TimeInstant.
public static TimeInstant
createTimeInstant(long time)
Given the value of milliseconds since January 1, 1970, 00:00:00
GMT, returns a TimeInstant.
public boolean equals(Object
object)
Indicates whether some other object is "equal to" this one.
Object.equals(Object)
public Calendar
getCalendar()
Returns the Calendar representation of this class
public int getCalendarYear()Get the Calendar year
DEPRECATED
public long getCentury()Returns the century (CC) field
public int getDay()Returns the day (DD) of the month field
public int getEra()Returns the era (+/-)
public int getHour()Returns the hour (hh) field
public int getMilliSeconds()Get the milliseconds portion of the second field. eg, 12.456 returns '456'
public int getMinute()Returns the minute (mm) field
public int getMonth()Returns the month (MM) field. The month is assumed to be indexed at 1 (eg, January=1, February=2)
public double getSecond()Returns the second (ss.sss) field with the milliseconds represented as a fraction of the second.
public int getSecondAsInt()Returns the integer part of the second field.
public double getTime()Returns the value of milliseconds since January 1, 1970, 00:00:00 GMT represented by this time instant object.
public TimeZone
getTimeZone()
Returns the time zone
DEPRECATED Use int getCalendarYear()
public long getYear()Returns the year (CCYY) field
public int getZoneHour()Returns the hour field of time zone
public int getZoneMinute()Returns the minute field of time zone
public boolean isTimeZoneUTC()Returns true if the time instant is based on UTC
publicTimeInstant
offset(TimeDuration
timeDuration)
Creates an offset of this TimeInstant with a given TimeDuration.
Note: This implementation does not guarantee the precision beyond those values representable by java.util.Calendar.
public void setCalendarYear(int year)Sets the year (CCYY) field
DEPRECATED
public void setCentury(long century)Sets the century (CC) field
public void setDay(int day)Sets the day (DD) of the month field
public void setEra(int era)Sets the era (+/-)
public void setHour(int hour)Sets the hour (hh) field
throwsIllegalArgumentException
IllegalArgumentException
public void setMilliSecond(int msec)Sets the milliseconds field as an integer
throwsIllegalArgumentException
IllegalArgumentException
public void setMinute(int minute)Sets the minute (mm) field
throwsIllegalArgumentException
IllegalArgumentException
public void setMonth(int month)Sets the month (MM) field. The month is assumed to be indexed at 1 (eg, January=1, February=2) for backward-compatability with the original code.
throwsIllegalArgumentException
IllegalArgumentException
public void setSecond(double second)Sets the second field in a fractional format
throwsIllegalArgumentException
IllegalArgumentException
public void setSecond(int second)Sets the second field as an integer
throwsIllegalArgumentException
IllegalArgumentException
public void setTimeZone(int zoneHour, int zoneMinute)Sets the time zone
public void setTimeZone(TimeZone
timeZone)
Sets the time zone
DEPRECATED Use setCalendarYear(int year) , eg, setCalendarYear(2004)
public void setYear(long century, int year)Sets the year (CCYY) field
throwsIllegalArgumentException
IllegalArgumentException
DEPRECATED Use setCalendarYear(int year)
public void setYear(long year)Sets the year (CCYY) field
public Date
toDate()
Returns java.util.Date representation of
timeInstant. Note that following:
publicDate
toDate(Calendar
calendarIn)
public TimeInstant
toLocal()
Offsets the current time instant to the local time zone.
Note: This implementation does not guarantee the precision beyond those values representable by java.util.Calendar.
public Date
toSQLDate()
Returns java.sql.Date representation of
timeInstant. Note that following:
public String
toString()
Returns a XML schema compliant timeInstant string.
This method uses the following rules:
The above rules imply that this method does not guarantee TimeInstant.createTimeInstant(_string).toString().equals(_string) to be true.
Object.toString()
public Timestamp
toTimestamp()
Returns java.sql.Timestamp representation of
timeInstant. Note that following:
public TimeInstant
toUTC()
Offsets the current time instant to UTC.
Note: This implementation does not guarantee the precision beyond those values representable by java.util.Calendar.