public final class IlvTimeUtil extends Object
IlvTimeUtil
class consists of static methods that
are of general use when working with Date
,
Calendar
, IlvDuration
, and IlvTimeInterval
objects.
This class is a singleton and instances of this class cannot be created.Modifier and Type | Field and Description |
---|---|
static Date |
MAX_VALUE
The largest value of type
Date . |
static Date |
MIN_VALUE
The smallest value of type
Date . |
Modifier and Type | Method and Description |
---|---|
static Date |
add(Date date,
IlvDuration delta)
Returns a new
Date that is the sum of the specified date and duration. |
static Date |
coerce(Object obj)
Coerces the specified object to a
Date . |
static IlvDuration |
max(IlvDuration a,
IlvDuration b)
Returns the greater of two
IlvDuration values. |
static IlvDuration |
min(IlvDuration a,
IlvDuration b)
Returns the smaller of two
IlvDuration values. |
static IlvDuration |
subtract(Date date1,
Date date2)
Returns the difference between the two specified dates.
|
static Date |
subtract(Date date,
IlvDuration delta)
Returns a new
Date that is the specified date minus the specified
duration. |
public static final Date MIN_VALUE
Date
.public static final Date MAX_VALUE
Date
.public static Date coerce(Object obj)
Date
. If the object
cannot be converted, an IllegalArgumentException
is thrown.
The following conversions are currently supported:
obj
is a Date
, it will simply be
returned as-is.obj
is a Number
, then a Date
will be constructed from its longValue()
, which represents
the number of milliseconds since January 1, 1970, 00:00:00 GMT.obj
- The object to coerce.public static Date add(Date date, IlvDuration delta)
Date
that is the sum of the specified date and duration.
Note that this method does not take account of Daylight Saving Time transitions or
other timezone and locale dependencies. For logical calendar computations you should
use methods of the java.util.Calendar
class and the IlvCalendarUtil
utility class. For example, to advance a Date
by one
logical day in the current default timezone and locale, you would use:
Calendar cal = Calendar.getInstance(); cal.setTime(aDate); cal.add(Calendar.DAY_OF_YEAR, 1); Date nextDay = cal.getTime();
date
- The date.delta
- The duration to add to the date.public static Date subtract(Date date, IlvDuration delta)
Date
that is the specified date minus the specified
duration. Note that this method does not take account of Daylight Saving Time
transitions or other timezone and locale dependencies. For logical calendar
computations you should use methods of the java.util.Calendar
class and
the IlvCalendarUtil
utility class. For example, to decrement a
Date
by one logical day in the current default timezone and locale, you
would use:
Calendar cal = Calendar.getInstance(); cal.setTime(aDate); cal.add(Calendar.DAY_OF_YEAR, -1); Date nextDay = cal.getTime();
date
- The date.delta
- The duration to subtract from the date.public static IlvDuration subtract(Date date1, Date date2)
date1
- The date.date2
- The date to subtract from date1.public static IlvDuration max(IlvDuration a, IlvDuration b)
IlvDuration
values.a
- A duration.b
- Another duration.a
and b
.public static IlvDuration min(IlvDuration a, IlvDuration b)
IlvDuration
values.a
- A duration.b
- Another duration.a
and b
.© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.