public class XdevDate extends GregorianCalendar implements Copyable<XdevDate>
XdevDate
represents a specific instant in time, with
millisecond precision.
The XdevDate
class provides common methods for date / time
manipulation, comparison and formatting.
Calendar.Builder
AD, BC
ALL_STYLES, AM, AM_PM, APRIL, areFieldsSet, AUGUST, DATE, DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH, DAY_OF_YEAR, DECEMBER, DST_OFFSET, ERA, FEBRUARY, FIELD_COUNT, fields, FRIDAY, HOUR, HOUR_OF_DAY, isSet, isTimeSet, JANUARY, JULY, JUNE, LONG, LONG_FORMAT, LONG_STANDALONE, MARCH, MAY, MILLISECOND, MINUTE, MONDAY, MONTH, NARROW_FORMAT, NARROW_STANDALONE, NOVEMBER, OCTOBER, PM, SATURDAY, SECOND, SEPTEMBER, SHORT, SHORT_FORMAT, SHORT_STANDALONE, SUNDAY, THURSDAY, time, TUESDAY, UNDECIMBER, WEDNESDAY, WEEK_OF_MONTH, WEEK_OF_YEAR, YEAR, ZONE_OFFSET
Constructor and Description |
---|
XdevDate()
Constructs a new
XdevDate using the current time in the default
time zone with the default locale. |
XdevDate(Calendar c)
|
XdevDate(Date d)
|
XdevDate(int year,
int month,
int day)
Constructs a new
XdevDate with the given date set in the default
time zone with the default locale. |
XdevDate(int year,
int month,
int day,
int hour,
int minute)
Constructs a new
XdevDate with the given date set in the default
time zone with the default locale. |
XdevDate(int year,
int month,
int day,
int hour,
int minute,
int second)
Constructs a new
XdevDate with the given date set in the default
time zone with the default locale. |
XdevDate(Locale locale)
Constructs a
XdevDate based on the current time in the default
time zone with the given locale. |
XdevDate(long currentTimeMillis)
Constructs a new
XdevDate using the time from the given long
value. |
XdevDate(TimeZone zone)
Constructs a
XdevDate based on the current time in the given time
zone with the default locale. |
XdevDate(TimeZone zone,
Locale locale)
Constructs a
XdevDate based on the current time in the given time
zone with the given locale. |
Modifier and Type | Method and Description |
---|---|
void |
add(int field,
int amount) |
boolean |
after(Object date)
|
boolean |
before(Object date)
|
boolean |
between(Object startDate,
Object endDate)
This method is a alias for
isBetween(Object, Object) . |
XdevDate |
clone()
Returns a field-for-field copy of this instance.
|
XdevDate |
copy()
Creates a (defensive) copy of this
XdevDate . |
boolean |
equals(Calendar other)
Indicates whether some other
Calendar object's date and time is
"equal to" this one. |
boolean |
equals(Date other)
Indicates whether some other
Date object's date and time is
"equal to" this one. |
boolean |
equals(Object other)
Indicates whether some other
XdevDate object's date and time is
"equal to" this one. |
boolean |
equalsDate(Object other)
|
boolean |
equalsTime(Object other)
|
String |
format(String pattern)
Returns a String representation of this
XdevDate . |
int |
get(int field) |
int |
getDay()
Returns the day of the month of this date.
|
Duration |
getDurationBetween(Object date)
Computes the duraction between
date and this
XdevDate . |
Duration |
getDurationSince(Object sooner)
Computes the duraction between
sooner and this
XdevDate . |
Duration |
getDurationUntil(Object later)
Computes the duraction between this
XdevDate and
later . |
DateFormat |
getFormat()
Returns the
DateFormat for this XdevDate . |
int |
getHour()
Returns the hour of this time using the 24-hour clock.
|
int |
getMinute()
Returns the minute of this time.
|
int |
getMonth()
Returns the month of this date.
|
int |
getSecond()
Returns the second of this time.
|
int |
getYear()
Returns the year of this date.
|
boolean |
isAfter(Object date)
This method is a alias for
after(Object) . |
boolean |
isBefore(Object date)
This method is a alias for
before(Object) . |
boolean |
isBetween(Object startDate,
Object endDate)
|
boolean |
isLeapYear()
Determines if the year of this
XdevDate is a leap year. |
XdevDate |
minus(Duration duration)
Creates a new
XdevDate whith this moment of time minus the
duration 's time. |
static XdevDate |
now()
Returns a new
XdevDate using the current time in the default time
zone with the default locale. |
XdevDate |
plus(Duration duration)
Creates a new
XdevDate whith this moment of time plus the
duration 's time. |
void |
roll(int field,
int amount) |
XdevDate |
rollBack(Duration duration)
Rolls this time to the past.
|
XdevDate |
rollForward(Duration duration)
Rolls this time to the future.
|
void |
set(int field,
int value) |
void |
setFormat(DateFormat format)
Sets the
DateFormat for this XdevDate . |
long |
timeStamp()
Returns this XdevDate's time value in milliseconds.
|
Date |
toDate()
|
String |
toString() |
computeFields, computeTime, from, getActualMaximum, getActualMinimum, getCalendarType, getGreatestMinimum, getGregorianChange, getLeastMaximum, getMaximum, getMinimum, getTimeZone, getWeeksInWeekYear, getWeekYear, hashCode, isLeapYear, isWeekDateSupported, roll, setGregorianChange, setTimeZone, setWeekDate, toZonedDateTime
clear, clear, compareTo, complete, getAvailableCalendarTypes, getAvailableLocales, getDisplayName, getDisplayNames, getFirstDayOfWeek, getInstance, getInstance, getInstance, getInstance, getMinimalDaysInFirstWeek, getTime, getTimeInMillis, internalGet, isLenient, isSet, set, set, set, setFirstDayOfWeek, setLenient, setMinimalDaysInFirstWeek, setTime, setTimeInMillis, toInstant
public XdevDate()
XdevDate
using the current time in the default
time zone with the default locale.public XdevDate(long currentTimeMillis)
XdevDate
using the time from the given long
value.currentTimeMillis
- the time in UTC milliseconds from the epoch.Calendar.setTime(Date)
,
Calendar.getTimeInMillis()
public XdevDate(int year, int month, int day)
XdevDate
with the given date set in the default
time zone with the default locale.year
- the value used to set the year of this date.month
- the value used to set the month of this date. Month value is
0-based. e.g., 0 for January.day
- the value used to set the day of this date.public XdevDate(int year, int month, int day, int hour, int minute)
XdevDate
with the given date set in the default
time zone with the default locale.year
- the value used to set the year of this date.month
- the value used to set the month of this date. Month value is
0-based. e.g., 0 for January.day
- the value used to set the day of this date.hour
- the value used to set the hour of this date.minute
- the value used to set the minute of this date.public XdevDate(int year, int month, int day, int hour, int minute, int second)
XdevDate
with the given date set in the default
time zone with the default locale.year
- the value used to set the year of this date.month
- the value used to set the month of this date. Month value is
0-based. e.g., 0 for January.day
- the value used to set the day of this date.hour
- the value used to set the hour of this date.minute
- the value used to set the minute of this date.second
- the value used to set the second of this date.public XdevDate(Locale locale)
XdevDate
based on the current time in the default
time zone with the given locale.locale
- the given locale.public XdevDate(TimeZone zone, Locale locale)
XdevDate
based on the current time in the given time
zone with the given locale.zone
- the given time zone.locale
- the given locale.public XdevDate(TimeZone zone)
XdevDate
based on the current time in the given time
zone with the default locale.zone
- the given time zone.public static XdevDate now()
XdevDate
using the current time in the default time
zone with the default locale.XdevDate
XdevDate()
public void add(int field, int amount)
add
in class GregorianCalendar
public void roll(int field, int amount)
roll
in class GregorianCalendar
public int getYear()
This is a convenience method for get(XdevDate.YEAR)
.
public int getMonth()
This is a convenience method for get(XdevDate.MONTH)
.
public int getDay()
This is a convenience method for get(XdevDate.DAY_OF_MONTH)
.
public int getHour()
This is a convenience method for get(XdevDate.HOUR_OF_DAY)
.
public int getMinute()
This is a convenience method for get(XdevDate.MINUTE)
.
public int getSecond()
This is a convenience method for get(XdevDate.SECOND)
.
public boolean equals(Object other)
XdevDate
object's date and time is
"equal to" this one.
XdevDate christmas = new XdevDate(2000,12,25,12,00); XdevDate newYearsEve = new XdevDate(2000,12,31,12,00); christmas.equals(newYearsEve) returns false christmas.equals(christmas) returns true
equals
in class GregorianCalendar
other
- the reference object with which to compare.true
if this object's date and time is the same as
the other argument's date; false
otherwise.equalsTime(Object)
,
equalsDate(Object)
public boolean equals(Date other)
Date
object's date and time is
"equal to" this one.
XdevDate christmas = new XdevDate(2000,12,25,12,00); XdevDate newYearsEve = new XdevDate(2000,12,31,12,00); christmas.equals(newYearsEve) returns false christmas.equals(christmas) returns true
other
- the reference object with which to compare.true
if this object's date and time is the same as
the other argument's date; false
otherwise.equalsTime(Object)
,
equalsDate(Object)
public boolean equals(Calendar other)
Calendar
object's date and time is
"equal to" this one.
XdevDate christmas = new XdevDate(2000,12,25,12,00); XdevDate newYearsEve = new XdevDate(2000,12,31,12,00); christmas.equals(newYearsEve) returns false christmas.equals(christmas) returns true
other
- the reference object with which to compare.true
if this object's date and time is the same as
the other argument's date; false
otherwise.equalsTime(Object)
,
equalsDate(Object)
public boolean equalsDate(Object other) throws IllegalArgumentException
Date
or Calendar
object's
date is "equal to" this one.
XdevDate christmas = new XdevDate(2000,12,25,12,00); XdevDate christmasEve = new XdevDate(2000,12,24,18,00); christmas.equalsDate(christmasEve) returns false christmas.equalsDate(christmas) returns true
other
- the reference object with which to compare.true
if this object's date is the same as the other
argument's date; false
otherwise.IllegalArgumentException
- if other
is not a instance of Calendar
or Date
.equalsTime(Object)
,
equals(Object)
public boolean equalsTime(Object other) throws IllegalArgumentException
Date
or Calendar
object's
time is "equal to" this one.
XdevDate christmas = new XdevDate(2000,12,25,12,00); XdevDate christmasEve = new XdevDate(2000,12,24,18,00); XdevDate newYearsEve = new XdevDate(2000,12,31,12,00); christmas.equalsDate(newYearsEve) returns true christmas.equalsDate(christmas) returns true christmas.equalsDate(christmasEve) returns false
other
- the reference object with which to compare.true
if this object's time is the same as the other
argument's time; false
otherwise.IllegalArgumentException
- if other
is not a instance of Calendar
or Date
.equalsDate(Object)
,
equalsTime(Object)
public boolean isAfter(Object date) throws IllegalArgumentException
after(Object)
.date
- the Object to be compared.true
if the time of this XdevDate
is after
the time represented by when; false
otherwise.IllegalArgumentException
- if other
is not a instance of Calendar
or Date
.after(Object)
,
before(Object)
,
isBefore(Object)
,
between(Object, Object)
,
isBetween(Object, Object)
public boolean after(Object date) throws IllegalArgumentException
XdevDate
represents a date/time after the
date/time represented by the specified Object
date
.
XdevDate christmas = new XdevDate(2000,12,25,12,00); XdevDate newYearsEve = new XdevDate(2000,12,31,12,00); christmas.after(newYearsEve) returns false christmas.after(christmas) returns false newYearsEve.after(christmas) returns true
after
in class Calendar
date
- the Object to be compared.true
if the time of this XdevDate
is after
the time represented by when; false
otherwise.IllegalArgumentException
- if other
is not a instance of Calendar
or Date
.before(Object)
,
isBefore(Object)
,
between(Object, Object)
,
isBetween(Object, Object)
public boolean isBefore(Object date) throws IllegalArgumentException
before(Object)
.date
- the Object to be compared.true
if the time of this XdevDate
is before
the time represented by when; false
otherwise.IllegalArgumentException
- if other
is not a instance of Calendar
or Date
.before(Object)
,
after(Object)
,
isAfter(Object)
,
between(Object, Object)
,
isBetween(Object, Object)
public boolean before(Object date) throws IllegalArgumentException
XdevDate
represents a date/time before the
date/time represented by the specified Object
date
.
XdevDate christmas = new XdevDate(2000,12,25,12,00); XdevDate newYearsEve = new XdevDate(2000,12,31,12,00); christmas.before(newYearsEve) returns ture christmas.before(christmas) returns false newYearsEve.before(christmas) returns false
before
in class Calendar
date
- the Object to be compared.true
if the time of this XdevDate
is before
the time represented by when; false
otherwise.IllegalArgumentException
- if other
is not a instance of Calendar
or Date
.after(Object)
,
isAfter(Object)
,
between(Object, Object)
,
isBetween(Object, Object)
public boolean between(Object startDate, Object endDate) throws IllegalArgumentException
isBetween(Object, Object)
.startDate
- the Object to be compared.endDate
- the Object to be compared.true
if the time of this XdevDate
is before
the time represented by when; false
otherwise.IllegalArgumentException
- if startDate
or endDate
is not a
instance of Calendar
or Date
.after(Object)
,
isAfter(Object)
,
between(Object, Object)
public boolean isBetween(Object startDate, Object endDate) throws IllegalArgumentException
XdevDate
represents a date/time between the
date/time represented by the specified Object
startDate
and endDate
.
XdevDate christmasEve = new XdevDate(2000,12,24,18,00); XdevDate christmas = new XdevDate(2000,12,25,12,00); XdevDate newYearsEve = new XdevDate(2000,12,31,12,00); christmas.isBetween(christmasEve, newYearsEve) returns ture christmasEve.isBetween(christmas, newYearsEve) returns false
startDate
- the Object to be compared.endDate
- the Object to be compared.true
if the time of this XdevDate
is before
the time represented by when; false
otherwise.IllegalArgumentException
- if startDate
or endDate
is not a
instance of Calendar
or Date
.after(Object)
,
isAfter(Object)
,
between(Object, Object)
public boolean isLeapYear()
XdevDate
is a leap year. Returns
true
if this year is a leap year.true
if the year this XdevDate
is a leap
year; false
otherwise.public void setFormat(DateFormat format)
DateFormat
for this XdevDate
.format
- DateFormat
to be set.public DateFormat getFormat()
DateFormat
for this XdevDate
.DateFormat
of this XdevDate
.public Date toDate()
Date
representing the time value.Calendar.setTime(Date)
,
Calendar.getTimeInMillis()
public String format(String pattern) throws NullPointerException, IllegalArgumentException
XdevDate
. Formatted
according to the given pattern
.pattern
- SimpleDateFormat
pattern to format the String.XdevDate
.NullPointerException
- if the given pattern is nullIllegalArgumentException
- if the given pattern is invalidSimpleDateFormat
public long timeStamp()
Calendar.getTime()
,
Calendar.setTimeInMillis(long)
public Duration getDurationUntil(Object later)
XdevDate
and
later
.later
- A future timelater
public Duration getDurationSince(Object sooner)
sooner
and this
XdevDate
.sooner
- A past timesooner
and thispublic Duration getDurationBetween(Object date)
date
and this
XdevDate
.
It doesn't matter if date
is before this
or
vice versa.
date
- A datedate
and thispublic XdevDate rollForward(Duration duration)
duration
- The duration to be addedpublic XdevDate rollBack(Duration duration)
duration
- The duration to be removedpublic XdevDate plus(Duration duration)
XdevDate
whith this moment of time plus the
duration
's time.duration
- The duration to be addedXdevDate
public XdevDate minus(Duration duration)
XdevDate
whith this moment of time minus the
duration
's time.duration
- The duration to be removedXdevDate
public XdevDate copy()
XdevDate
.XdevDate
.Copyright © 2003–2021 XDEV Software. All rights reserved.