public abstract class DateUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
DateUtil.DateTimeUtil |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ISO_8601_DATETIME_FORMAT
It's default date/time format.
|
static java.lang.String |
ISO_8601_TIMESTAMP_FORMAT
It's default timestamp format.
|
static java.lang.String |
LOCAL_DATE_FORMAT |
static java.lang.String |
LOCAL_DATETIME_FORMAT |
static java.lang.String |
LOCAL_MONTH_DAY_FORMAT |
static java.lang.String |
LOCAL_TIME_FORMAT |
static java.util.TimeZone |
LOCAL_TIME_ZONE
The system default time zone
|
static java.lang.String |
LOCAL_TIMESTAMP_FORMAT |
static java.lang.String |
LOCAL_YEAR_FORMAT
Date format.
|
static java.lang.String |
RFC1123_DATE_FORMAT
This constant defines the date format specified by
RFC 1123 / RFC 822.
|
static int |
SEMI_MONTH
This is half a month, so this represents whether a date is in the top
or bottom half of the month.
|
static java.util.TimeZone |
UTC_TIME_ZONE |
Modifier and Type | Method and Description |
---|---|
static <T extends java.util.Calendar> |
addDays(T calendar,
int amount)
Adds a number of days to a calendar returning a new object.
|
static <T extends java.util.Date> |
addDays(T date,
int amount)
Adds a number of days to a date returning a new object.
|
static <T extends java.util.Calendar> |
addHours(T calendar,
int amount)
Adds a number of hours to a calendar returning a new object.
|
static <T extends java.util.Date> |
addHours(T date,
int amount)
Adds a number of hours to a date returning a new object.
|
static <T extends java.util.Calendar> |
addMilliseconds(T calendar,
int amount)
Adds a number of milliseconds to a calendar returning a new object.
|
static <T extends java.util.Date> |
addMilliseconds(T date,
int amount)
Adds a number of milliseconds to a date returning a new object.
|
static <T extends java.util.Calendar> |
addMinutes(T calendar,
int amount)
Adds a number of minutes to a calendar returning a new object.
|
static <T extends java.util.Date> |
addMinutes(T date,
int amount)
Adds a number of minutes to a date returning a new object.
|
static <T extends java.util.Calendar> |
addMonths(T calendar,
int amount)
Adds a number of months to a calendar returning a new object.
|
static <T extends java.util.Date> |
addMonths(T date,
int amount)
Adds a number of months to a date returning a new object.
|
static <T extends java.util.Calendar> |
addSeconds(T calendar,
int amount)
Adds a number of seconds to a calendar returning a new object.
|
static <T extends java.util.Date> |
addSeconds(T date,
int amount)
Adds a number of seconds to a date returning a new object.
|
static <T extends java.util.Calendar> |
addWeeks(T calendar,
int amount)
Adds a number of weeks to a calendar returning a new object.
|
static <T extends java.util.Date> |
addWeeks(T date,
int amount)
Adds a number of weeks to a date returning a new object.
|
static <T extends java.util.Calendar> |
addYears(T calendar,
int amount)
Adds a number of years to a calendar returning a new object.
|
static <T extends java.util.Date> |
addYears(T date,
int amount)
Adds a number of years to a date returning a new object.
|
static <T extends java.util.Calendar> |
ceiling(T calendar,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends java.util.Date> |
ceiling(T date,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static java.util.Calendar |
createCalendar(java.util.Calendar calendar) |
static java.util.Calendar |
createCalendar(java.util.Date date) |
static java.util.Calendar |
createCalendar(long timeInMillis) |
static java.util.Calendar |
createCalendar(long timeInMillis,
java.util.TimeZone tz) |
static java.sql.Date |
createDate(java.util.Calendar calendar) |
static java.sql.Date |
createDate(java.util.Date date) |
static java.sql.Date |
createDate(long timeInMillis) |
static java.util.GregorianCalendar |
createGregorianCalendar(java.util.Calendar calendar) |
static java.util.GregorianCalendar |
createGregorianCalendar(java.util.Date date) |
static java.util.GregorianCalendar |
createGregorianCalendar(long timeInMillis) |
static java.util.GregorianCalendar |
createGregorianCalendar(long timeInMillis,
java.util.TimeZone tz) |
static java.util.Date |
createJUDate(java.util.Calendar calendar) |
static java.util.Date |
createJUDate(java.util.Date date) |
static java.util.Date |
createJUDate(long timeInMillis) |
static java.sql.Time |
createTime(java.util.Calendar calendar) |
static java.sql.Time |
createTime(java.util.Date date) |
static java.sql.Time |
createTime(long timeInMillis) |
static java.sql.Timestamp |
createTimestamp(java.util.Calendar calendar) |
static java.sql.Timestamp |
createTimestamp(java.util.Date date) |
static java.sql.Timestamp |
createTimestamp(long timeInMillis) |
static javax.xml.datatype.XMLGregorianCalendar |
createXMLGregorianCalendar(java.util.Calendar calendar) |
static javax.xml.datatype.XMLGregorianCalendar |
createXMLGregorianCalendar(java.util.Date date) |
static javax.xml.datatype.XMLGregorianCalendar |
createXMLGregorianCalendar(long timeInMillis) |
static java.util.Calendar |
currentCalendar()
A new instance of
java.util.Calendar returned is based on
the current time in the default time zone with the default locale. |
static java.sql.Date |
currentDate()
A new instance of
java.sql.Date returned is based on the
current time in the default time zone with the default locale. |
static java.util.GregorianCalendar |
currentGregorianCalendar() |
static java.util.Date |
currentJUDate()
A new instance of
java.util.Date returned is based on the
current time in the default time zone with the default locale. |
static java.sql.Time |
currentTime()
A new instance of
java.sql.Time returned is based on the
current time in the default time zone with the default locale. |
static java.sql.Timestamp |
currentTimestamp()
A new instance of
java.sql.Timestamp returned is based on
the current time in the default time zone with the default locale. |
static javax.xml.datatype.XMLGregorianCalendar |
currentXMLGregorianCalendar() |
static java.lang.String |
format(java.util.Calendar c) |
static java.lang.String |
format(java.util.Calendar c,
java.lang.String format) |
static java.lang.String |
format(java.util.Calendar c,
java.lang.String format,
java.util.TimeZone timeZone) |
static java.lang.String |
format(java.util.Date date) |
static java.lang.String |
format(java.util.Date date,
java.lang.String format) |
static java.lang.String |
format(java.util.Date date,
java.lang.String format,
java.util.TimeZone timeZone) |
static void |
format(java.io.Writer writer,
java.util.Calendar c) |
static void |
format(java.io.Writer writer,
java.util.Calendar c,
java.lang.String format) |
static void |
format(java.io.Writer writer,
java.util.Calendar c,
java.lang.String format,
java.util.TimeZone timeZone) |
static void |
format(java.io.Writer writer,
java.util.Date date) |
static void |
format(java.io.Writer writer,
java.util.Date date,
java.lang.String format) |
static void |
format(java.io.Writer writer,
java.util.Date date,
java.lang.String format,
java.util.TimeZone timeZone) |
static void |
format(java.io.Writer writer,
javax.xml.datatype.XMLGregorianCalendar c) |
static void |
format(java.io.Writer writer,
javax.xml.datatype.XMLGregorianCalendar c,
java.lang.String format) |
static void |
format(java.io.Writer writer,
javax.xml.datatype.XMLGregorianCalendar c,
java.lang.String format,
java.util.TimeZone timeZone) |
static java.lang.String |
format(javax.xml.datatype.XMLGregorianCalendar c) |
static java.lang.String |
format(javax.xml.datatype.XMLGregorianCalendar c,
java.lang.String format) |
static java.lang.String |
format(javax.xml.datatype.XMLGregorianCalendar c,
java.lang.String format,
java.util.TimeZone timeZone) |
static java.util.Calendar |
parseCalendar(java.lang.String calendar) |
static java.util.Calendar |
parseCalendar(java.lang.String calendar,
java.lang.String format) |
static java.util.Calendar |
parseCalendar(java.lang.String calendar,
java.lang.String format,
java.util.TimeZone timeZone)
Converts the specified
calendar with the specified format to a new instance of Calendar. |
static java.sql.Date |
parseDate(java.lang.String date) |
static java.sql.Date |
parseDate(java.lang.String date,
java.lang.String format) |
static java.sql.Date |
parseDate(java.lang.String date,
java.lang.String format,
java.util.TimeZone timeZone)
Converts the specified
date with the specified format to a new instance of java.sql.Date. |
static java.util.GregorianCalendar |
parseGregorianCalendar(java.lang.String calendar) |
static java.util.GregorianCalendar |
parseGregorianCalendar(java.lang.String calendar,
java.lang.String format) |
static java.util.GregorianCalendar |
parseGregorianCalendar(java.lang.String calendar,
java.lang.String format,
java.util.TimeZone timeZone)
Converts the specified
calendar with the specified format to a new instance of GregorianCalendar. |
static java.util.Date |
parseJUDate(java.lang.String date) |
static java.util.Date |
parseJUDate(java.lang.String date,
java.lang.String format) |
static java.util.Date |
parseJUDate(java.lang.String date,
java.lang.String format,
java.util.TimeZone timeZone)
Converts the specified
date with the specified format to a new instance of java.util.Date. |
static java.sql.Time |
parseTime(java.lang.String date) |
static java.sql.Time |
parseTime(java.lang.String date,
java.lang.String format) |
static java.sql.Time |
parseTime(java.lang.String date,
java.lang.String format,
java.util.TimeZone timeZone)
Converts the specified
date with the specified format to a new instance of Time. |
static java.sql.Timestamp |
parseTimestamp(java.lang.String date) |
static java.sql.Timestamp |
parseTimestamp(java.lang.String date,
java.lang.String format) |
static java.sql.Timestamp |
parseTimestamp(java.lang.String date,
java.lang.String format,
java.util.TimeZone timeZone)
Converts the specified
date with the specified format to a new instance of Timestamp. |
static javax.xml.datatype.XMLGregorianCalendar |
parseXMLGregorianCalendar(java.lang.String calendar) |
static javax.xml.datatype.XMLGregorianCalendar |
parseXMLGregorianCalendar(java.lang.String calendar,
java.lang.String format) |
static javax.xml.datatype.XMLGregorianCalendar |
parseXMLGregorianCalendar(java.lang.String calendar,
java.lang.String format,
java.util.TimeZone timeZone)
Converts the specified
calendar with the specified format to a new instance of XMLGregorianCalendar. |
static <T extends java.util.Calendar> |
roll(T calendar,
long amount,
CalendarUnit unit)
Deprecated.
replaced by
addYears/addMonths/addWeeks/... |
static <T extends java.util.Date> |
roll(T date,
long amount,
CalendarUnit unit)
Deprecated.
replaced by
addYears/addMonths/addWeeks/... |
static <T extends java.util.Calendar> |
roll(T calendar,
long amount,
java.util.concurrent.TimeUnit unit)
Deprecated.
replaced by
addYears/addMonths/addWeeks/... |
static <T extends java.util.Date> |
roll(T date,
long amount,
java.util.concurrent.TimeUnit unit)
Deprecated.
replaced by
addYears/addMonths/addWeeks/... |
static <T extends java.util.Calendar> |
round(T calendar,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends java.util.Date> |
round(T date,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends java.util.Date> |
setDays(T date,
int amount)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends java.util.Date> |
setHours(T date,
int amount)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends java.util.Date> |
setMilliseconds(T date,
int amount)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends java.util.Date> |
setMinutes(T date,
int amount)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends java.util.Date> |
setMonths(T date,
int amount)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends java.util.Date> |
setSeconds(T date,
int amount)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends java.util.Date> |
setYears(T date,
int amount)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends java.util.Calendar> |
truncate(T calendar,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends java.util.Date> |
truncate(T date,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static int |
truncatedCompareTo(java.util.Calendar cal1,
java.util.Calendar cal2,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static int |
truncatedCompareTo(java.util.Date date1,
java.util.Date date2,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static boolean |
truncatedEquals(java.util.Calendar cal1,
java.util.Calendar cal2,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static boolean |
truncatedEquals(java.util.Date date1,
java.util.Date date2,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
public static final java.util.TimeZone UTC_TIME_ZONE
public static final java.util.TimeZone LOCAL_TIME_ZONE
public static final java.lang.String LOCAL_YEAR_FORMAT
public static final java.lang.String LOCAL_MONTH_DAY_FORMAT
public static final java.lang.String LOCAL_DATE_FORMAT
public static final java.lang.String LOCAL_TIME_FORMAT
public static final java.lang.String LOCAL_DATETIME_FORMAT
public static final java.lang.String LOCAL_TIMESTAMP_FORMAT
public static final java.lang.String ISO_8601_DATETIME_FORMAT
public static final java.lang.String ISO_8601_TIMESTAMP_FORMAT
public static final java.lang.String RFC1123_DATE_FORMAT
public static final int SEMI_MONTH
public static java.sql.Time currentTime()
java.sql.Time
returned is based on the
current time in the default time zone with the default locale.public static java.sql.Date currentDate()
java.sql.Date
returned is based on the
current time in the default time zone with the default locale.public static java.sql.Timestamp currentTimestamp()
java.sql.Timestamp
returned is based on
the current time in the default time zone with the default locale.public static java.util.Date currentJUDate()
java.util.Date
returned is based on the
current time in the default time zone with the default locale.public static java.util.Calendar currentCalendar()
java.util.Calendar
returned is based on
the current time in the default time zone with the default locale.public static java.util.GregorianCalendar currentGregorianCalendar()
public static javax.xml.datatype.XMLGregorianCalendar currentXMLGregorianCalendar()
public static java.util.Date createJUDate(java.util.Calendar calendar)
public static java.util.Date createJUDate(java.util.Date date)
public static java.util.Date createJUDate(long timeInMillis)
public static java.sql.Date createDate(java.util.Calendar calendar)
public static java.sql.Date createDate(java.util.Date date)
public static java.sql.Date createDate(long timeInMillis)
public static java.sql.Time createTime(java.util.Calendar calendar)
public static java.sql.Time createTime(java.util.Date date)
public static java.sql.Time createTime(long timeInMillis)
public static java.sql.Timestamp createTimestamp(java.util.Calendar calendar)
public static java.sql.Timestamp createTimestamp(java.util.Date date)
public static java.sql.Timestamp createTimestamp(long timeInMillis)
public static java.util.Calendar createCalendar(java.util.Calendar calendar)
public static java.util.Calendar createCalendar(java.util.Date date)
public static java.util.Calendar createCalendar(long timeInMillis)
public static java.util.Calendar createCalendar(long timeInMillis, java.util.TimeZone tz)
public static java.util.GregorianCalendar createGregorianCalendar(java.util.Calendar calendar)
public static java.util.GregorianCalendar createGregorianCalendar(java.util.Date date)
public static java.util.GregorianCalendar createGregorianCalendar(long timeInMillis)
public static java.util.GregorianCalendar createGregorianCalendar(long timeInMillis, java.util.TimeZone tz)
public static javax.xml.datatype.XMLGregorianCalendar createXMLGregorianCalendar(java.util.Calendar calendar)
public static javax.xml.datatype.XMLGregorianCalendar createXMLGregorianCalendar(java.util.Date date)
public static javax.xml.datatype.XMLGregorianCalendar createXMLGregorianCalendar(long timeInMillis)
public static java.util.Date parseJUDate(java.lang.String date)
public static java.util.Date parseJUDate(java.lang.String date, java.lang.String format)
public static java.util.Date parseJUDate(java.lang.String date, java.lang.String format, java.util.TimeZone timeZone)
date
with the specified format
to a new instance of java.util.Date.
null
is returned if the specified date
is null or empty.date
- format
- java.lang.IllegalArgumentException
- if the date given can't be parsed with specified format.public static java.sql.Date parseDate(java.lang.String date)
public static java.sql.Date parseDate(java.lang.String date, java.lang.String format)
public static java.sql.Date parseDate(java.lang.String date, java.lang.String format, java.util.TimeZone timeZone)
date
with the specified format
to a new instance of java.sql.Date.
null
is returned if the specified date
is null or empty.date
- format
- timeZone
- public static java.sql.Time parseTime(java.lang.String date)
public static java.sql.Time parseTime(java.lang.String date, java.lang.String format)
public static java.sql.Time parseTime(java.lang.String date, java.lang.String format, java.util.TimeZone timeZone)
date
with the specified format
to a new instance of Time.
null
is returned if the specified date
is null or empty.date
- format
- timeZone
- public static java.sql.Timestamp parseTimestamp(java.lang.String date)
public static java.sql.Timestamp parseTimestamp(java.lang.String date, java.lang.String format)
public static java.sql.Timestamp parseTimestamp(java.lang.String date, java.lang.String format, java.util.TimeZone timeZone)
date
with the specified format
to a new instance of Timestamp.
null
is returned if the specified date
is null or empty.date
- format
- timeZone
- public static java.util.Calendar parseCalendar(java.lang.String calendar)
public static java.util.Calendar parseCalendar(java.lang.String calendar, java.lang.String format)
public static java.util.Calendar parseCalendar(java.lang.String calendar, java.lang.String format, java.util.TimeZone timeZone)
calendar
with the specified format
to a new instance of Calendar.
null
is returned if the specified date
is null or empty.calendar
- format
- timeZone
- public static java.util.GregorianCalendar parseGregorianCalendar(java.lang.String calendar)
public static java.util.GregorianCalendar parseGregorianCalendar(java.lang.String calendar, java.lang.String format)
public static java.util.GregorianCalendar parseGregorianCalendar(java.lang.String calendar, java.lang.String format, java.util.TimeZone timeZone)
calendar
with the specified format
to a new instance of GregorianCalendar.
null
is returned if the specified date
is null or empty.calendar
- format
- timeZone
- public static javax.xml.datatype.XMLGregorianCalendar parseXMLGregorianCalendar(java.lang.String calendar)
public static javax.xml.datatype.XMLGregorianCalendar parseXMLGregorianCalendar(java.lang.String calendar, java.lang.String format)
public static javax.xml.datatype.XMLGregorianCalendar parseXMLGregorianCalendar(java.lang.String calendar, java.lang.String format, java.util.TimeZone timeZone)
calendar
with the specified format
to a new instance of XMLGregorianCalendar.
null
is returned if the specified date
is null or empty.calendar
- format
- timeZone
- public static java.lang.String format(java.util.Date date)
public static java.lang.String format(java.util.Date date, java.lang.String format)
public static java.lang.String format(java.util.Date date, java.lang.String format, java.util.TimeZone timeZone)
public static void format(java.io.Writer writer, java.util.Date date)
public static void format(java.io.Writer writer, java.util.Date date, java.lang.String format)
public static void format(java.io.Writer writer, java.util.Date date, java.lang.String format, java.util.TimeZone timeZone)
public static java.lang.String format(java.util.Calendar c)
public static java.lang.String format(java.util.Calendar c, java.lang.String format)
public static java.lang.String format(java.util.Calendar c, java.lang.String format, java.util.TimeZone timeZone)
public static void format(java.io.Writer writer, java.util.Calendar c)
public static void format(java.io.Writer writer, java.util.Calendar c, java.lang.String format)
public static void format(java.io.Writer writer, java.util.Calendar c, java.lang.String format, java.util.TimeZone timeZone)
public static java.lang.String format(javax.xml.datatype.XMLGregorianCalendar c)
public static java.lang.String format(javax.xml.datatype.XMLGregorianCalendar c, java.lang.String format)
public static java.lang.String format(javax.xml.datatype.XMLGregorianCalendar c, java.lang.String format, java.util.TimeZone timeZone)
public static void format(java.io.Writer writer, javax.xml.datatype.XMLGregorianCalendar c)
public static void format(java.io.Writer writer, javax.xml.datatype.XMLGregorianCalendar c, java.lang.String format)
public static void format(java.io.Writer writer, javax.xml.datatype.XMLGregorianCalendar c, java.lang.String format, java.util.TimeZone timeZone)
public static <T extends java.util.Date> T setYears(T date, int amount)
Date
is unchanged.date
- the date, not nullamount
- the amount to setDate
set with the specified valuejava.lang.IllegalArgumentException
- if the date is nullpublic static <T extends java.util.Date> T setMonths(T date, int amount)
Date
is unchanged.date
- the date, not nullamount
- the amount to setDate
set with the specified valuejava.lang.IllegalArgumentException
- if the date is nullpublic static <T extends java.util.Date> T setDays(T date, int amount)
Date
is unchanged.date
- the date, not nullamount
- the amount to setDate
set with the specified valuejava.lang.IllegalArgumentException
- if the date is nullpublic static <T extends java.util.Date> T setHours(T date, int amount)
Date
is unchanged.date
- the date, not nullamount
- the amount to setDate
set with the specified valuejava.lang.IllegalArgumentException
- if the date is nullpublic static <T extends java.util.Date> T setMinutes(T date, int amount)
Date
is unchanged.date
- the date, not nullamount
- the amount to setDate
set with the specified valuejava.lang.IllegalArgumentException
- if the date is nullpublic static <T extends java.util.Date> T setSeconds(T date, int amount)
Date
is unchanged.date
- the date, not nullamount
- the amount to setDate
set with the specified valuejava.lang.IllegalArgumentException
- if the date is nullpublic static <T extends java.util.Date> T setMilliseconds(T date, int amount)
Date
is unchanged.date
- the date, not nullamount
- the amount to setDate
set with the specified valuejava.lang.IllegalArgumentException
- if the date is null@Deprecated public static <T extends java.util.Date> T roll(T date, long amount, java.util.concurrent.TimeUnit unit)
addYears/addMonths/addWeeks/...
N.roll(date, -5, TimeUnit.DAYS)
.
date
- amount
- unit
- @Deprecated public static <T extends java.util.Date> T roll(T date, long amount, CalendarUnit unit)
addYears/addMonths/addWeeks/...
N.roll(date, -5, CalendarUnit.DAY)
.
date
- amount
- unit
- @Deprecated public static <T extends java.util.Calendar> T roll(T calendar, long amount, java.util.concurrent.TimeUnit unit)
addYears/addMonths/addWeeks/...
N.roll(c, -5, TimeUnit.DAYS)
.
calendar
- amount
- unit
- @Deprecated public static <T extends java.util.Calendar> T roll(T calendar, long amount, CalendarUnit unit)
addYears/addMonths/addWeeks/...
N.roll(c, -5, CalendarUnit.DAY)
.
calendar
- amount
- unit
- public static <T extends java.util.Date> T addYears(T date, int amount)
Date
is unchanged.date
- the date, not nullamount
- the amount to add, may be negativeDate
with the amount addedjava.lang.IllegalArgumentException
- if the date is nullpublic static <T extends java.util.Date> T addMonths(T date, int amount)
Date
is unchanged.date
- the date, not nullamount
- the amount to add, may be negativeDate
with the amount addedjava.lang.IllegalArgumentException
- if the date is nullpublic static <T extends java.util.Date> T addWeeks(T date, int amount)
Date
is unchanged.date
- the date, not nullamount
- the amount to add, may be negativeDate
with the amount addedjava.lang.IllegalArgumentException
- if the date is nullpublic static <T extends java.util.Date> T addDays(T date, int amount)
Date
is unchanged.date
- the date, not nullamount
- the amount to add, may be negativeDate
with the amount addedjava.lang.IllegalArgumentException
- if the date is nullpublic static <T extends java.util.Date> T addHours(T date, int amount)
Date
is unchanged.date
- the date, not nullamount
- the amount to add, may be negativeDate
with the amount addedjava.lang.IllegalArgumentException
- if the date is nullpublic static <T extends java.util.Date> T addMinutes(T date, int amount)
Date
is unchanged.date
- the date, not nullamount
- the amount to add, may be negativeDate
with the amount addedjava.lang.IllegalArgumentException
- if the date is nullpublic static <T extends java.util.Date> T addSeconds(T date, int amount)
Date
is unchanged.date
- the date, not nullamount
- the amount to add, may be negativeDate
with the amount addedjava.lang.IllegalArgumentException
- if the date is nullpublic static <T extends java.util.Date> T addMilliseconds(T date, int amount)
Date
is unchanged.date
- the date, not nullamount
- the amount to add, may be negativeDate
with the amount addedjava.lang.IllegalArgumentException
- if the date is nullpublic static <T extends java.util.Calendar> T addYears(T calendar, int amount)
Date
is unchanged.calendar
- the calendar, not nullamount
- the amount to add, may be negativeDate
with the amount addedjava.lang.IllegalArgumentException
- if the calendar is nullpublic static <T extends java.util.Calendar> T addMonths(T calendar, int amount)
Date
is unchanged.calendar
- the calendar, not nullamount
- the amount to add, may be negativeDate
with the amount addedjava.lang.IllegalArgumentException
- if the calendar is nullpublic static <T extends java.util.Calendar> T addWeeks(T calendar, int amount)
Date
is unchanged.calendar
- the calendar, not nullamount
- the amount to add, may be negativeDate
with the amount addedjava.lang.IllegalArgumentException
- if the calendar is nullpublic static <T extends java.util.Calendar> T addDays(T calendar, int amount)
Date
is unchanged.calendar
- the calendar, not nullamount
- the amount to add, may be negativeDate
with the amount addedjava.lang.IllegalArgumentException
- if the calendar is nullpublic static <T extends java.util.Calendar> T addHours(T calendar, int amount)
Date
is unchanged.calendar
- the calendar, not nullamount
- the amount to add, may be negativeDate
with the amount addedjava.lang.IllegalArgumentException
- if the calendar is nullpublic static <T extends java.util.Calendar> T addMinutes(T calendar, int amount)
Date
is unchanged.calendar
- the calendar, not nullamount
- the amount to add, may be negativeDate
with the amount addedjava.lang.IllegalArgumentException
- if the calendar is nullpublic static <T extends java.util.Calendar> T addSeconds(T calendar, int amount)
Date
is unchanged.calendar
- the calendar, not nullamount
- the amount to add, may be negativeDate
with the amount addedjava.lang.IllegalArgumentException
- if the calendar is nullpublic static <T extends java.util.Calendar> T addMilliseconds(T calendar, int amount)
Date
is unchanged.calendar
- the calendar, not nullamount
- the amount to add, may be negativeDate
with the amount addedjava.lang.IllegalArgumentException
- if the calendar is nullpublic static <T extends java.util.Date> T round(T date, int field)
Rounds a date, leaving the field specified as the most significant field.
For example, if you had the date-time of 28 Mar 2002 13:45:01.231, if this was passed with HOUR, it would return 28 Mar 2002 14:00:00.000. If this was passed with MONTH, it would return 1 April 2002 0:00:00.000.
For a date in a timezone that handles the change to daylight saving time, rounding to Calendar.HOUR_OF_DAY will behave as follows. Suppose daylight saving time begins at 02:00 on March 30. Rounding a date that crosses this time would produce the following values:
date
- the date to work with, not nullfield
- the field from Calendar
or SEMI_MONTH
java.lang.ArithmeticException
- if the year is over 280 millionpublic static <T extends java.util.Calendar> T round(T calendar, int field)
Rounds a date, leaving the field specified as the most significant field.
For example, if you had the date-time of 28 Mar 2002 13:45:01.231, if this was passed with HOUR, it would return 28 Mar 2002 14:00:00.000. If this was passed with MONTH, it would return 1 April 2002 0:00:00.000.
For a date in a timezone that handles the change to daylight saving time, rounding to Calendar.HOUR_OF_DAY will behave as follows. Suppose daylight saving time begins at 02:00 on March 30. Rounding a date that crosses this time would produce the following values:
calendar
- the date to work with, not nullfield
- the field from Calendar
or SEMI_MONTH
java.lang.IllegalArgumentException
- if the date is null
java.lang.ArithmeticException
- if the year is over 280 millionpublic static <T extends java.util.Date> T truncate(T date, int field)
Truncates a date, leaving the field specified as the most significant field.
For example, if you had the date-time of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000. If this was passed with MONTH, it would return 1 Mar 2002 0:00:00.000.
date
- the date to work with, not nullfield
- the field from Calendar
or SEMI_MONTH
java.lang.IllegalArgumentException
- if the date is null
java.lang.ArithmeticException
- if the year is over 280 millionpublic static <T extends java.util.Calendar> T truncate(T calendar, int field)
Truncates a date, leaving the field specified as the most significant field.
For example, if you had the date-time of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000. If this was passed with MONTH, it would return 1 Mar 2002 0:00:00.000.
calendar
- the date to work with, not nullfield
- the field from Calendar
or SEMI_MONTH
java.lang.IllegalArgumentException
- if the date is null
java.lang.ArithmeticException
- if the year is over 280 millionpublic static <T extends java.util.Date> T ceiling(T date, int field)
Gets a date ceiling, leaving the field specified as the most significant field.
For example, if you had the date-time of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 14:00:00.000. If this was passed with MONTH, it would return 1 Apr 2002 0:00:00.000.
date
- the date to work with, not nullfield
- the field from Calendar
or SEMI_MONTH
java.lang.IllegalArgumentException
- if the date is null
java.lang.ArithmeticException
- if the year is over 280 millionpublic static <T extends java.util.Calendar> T ceiling(T calendar, int field)
Gets a date ceiling, leaving the field specified as the most significant field.
For example, if you had the date-time of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 14:00:00.000. If this was passed with MONTH, it would return 1 Apr 2002 0:00:00.000.
calendar
- the date to work with, not nullfield
- the field from Calendar
or SEMI_MONTH
java.lang.IllegalArgumentException
- if the date is null
java.lang.ArithmeticException
- if the year is over 280 millionpublic static boolean truncatedEquals(java.util.Calendar cal1, java.util.Calendar cal2, int field)
cal1
- the first calendar, not null
cal2
- the second calendar, not null
field
- the field from Calendar
true
if equal; otherwise false
java.lang.IllegalArgumentException
- if any argument is null
truncate(Calendar, int)
,
truncatedEquals(Date, Date, int)
public static boolean truncatedEquals(java.util.Date date1, java.util.Date date2, int field)
date1
- the first date, not null
date2
- the second date, not null
field
- the field from Calendar
true
if equal; otherwise false
java.lang.IllegalArgumentException
- if any argument is null
truncate(Date, int)
,
truncatedEquals(Calendar, Calendar, int)
public static int truncatedCompareTo(java.util.Calendar cal1, java.util.Calendar cal2, int field)
cal1
- the first calendar, not null
cal2
- the second calendar, not null
field
- the field from Calendar
java.lang.IllegalArgumentException
- if any argument is null
truncate(Calendar, int)
,
truncatedCompareTo(Date, Date, int)
public static int truncatedCompareTo(java.util.Date date1, java.util.Date date2, int field)
date1
- the first date, not null
date2
- the second date, not null
field
- the field from Calendar
java.lang.IllegalArgumentException
- if any argument is null
truncate(Calendar, int)
,
truncatedCompareTo(Date, Date, int)