public abstract class DateUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
DateUtil.DateTimeUtil
The Class DateTimeUtil.
|
Modifier and Type | Field and Description |
---|---|
static String |
ISO_8601_DATETIME_FORMAT
It's default date/time format.
|
static String |
ISO_8601_TIMESTAMP_FORMAT
It's default timestamp format.
|
static String |
LOCAL_DATE_FORMAT |
static String |
LOCAL_DATETIME_FORMAT |
static String |
LOCAL_MONTH_DAY_FORMAT |
static String |
LOCAL_TIME_FORMAT |
static TimeZone |
LOCAL_TIME_ZONE |
static String |
LOCAL_TIMESTAMP_FORMAT |
static String |
LOCAL_YEAR_FORMAT
Date format.
|
static 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 TimeZone |
UTC_TIME_ZONE |
Modifier and Type | Method and Description |
---|---|
static <T extends Calendar> |
addDays(T calendar,
int amount)
Adds a number of days to a calendar returning a new object.
|
static <T extends Date> |
addDays(T date,
int amount)
Adds a number of days to a date returning a new object.
|
static <T extends Calendar> |
addHours(T calendar,
int amount)
Adds a number of hours to a calendar returning a new object.
|
static <T extends Date> |
addHours(T date,
int amount)
Adds a number of hours to a date returning a new object.
|
static <T extends Calendar> |
addMilliseconds(T calendar,
int amount)
Adds a number of milliseconds to a calendar returning a new object.
|
static <T extends Date> |
addMilliseconds(T date,
int amount)
Adds a number of milliseconds to a date returning a new object.
|
static <T extends Calendar> |
addMinutes(T calendar,
int amount)
Adds a number of minutes to a calendar returning a new object.
|
static <T extends Date> |
addMinutes(T date,
int amount)
Adds a number of minutes to a date returning a new object.
|
static <T extends Calendar> |
addMonths(T calendar,
int amount)
Adds a number of months to a calendar returning a new object.
|
static <T extends Date> |
addMonths(T date,
int amount)
Adds a number of months to a date returning a new object.
|
static <T extends Calendar> |
addSeconds(T calendar,
int amount)
Adds a number of seconds to a calendar returning a new object.
|
static <T extends Date> |
addSeconds(T date,
int amount)
Adds a number of seconds to a date returning a new object.
|
static <T extends Calendar> |
addWeeks(T calendar,
int amount)
Adds a number of weeks to a calendar returning a new object.
|
static <T extends Date> |
addWeeks(T date,
int amount)
Adds a number of weeks to a date returning a new object.
|
static <T extends Calendar> |
addYears(T calendar,
int amount)
Adds a number of years to a calendar returning a new object.
|
static <T extends Date> |
addYears(T date,
int amount)
Adds a number of years to a date returning a new object.
|
static <T extends Calendar> |
ceiling(T calendar,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends Date> |
ceiling(T date,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static Calendar |
createCalendar(Calendar calendar)
Creates the calendar.
|
static Calendar |
createCalendar(Date date)
Creates the calendar.
|
static Calendar |
createCalendar(long timeInMillis)
Creates the calendar.
|
static Calendar |
createCalendar(long timeInMillis,
TimeZone tz)
Creates the calendar.
|
static Date |
createDate(Calendar calendar)
Creates the date.
|
static Date |
createDate(Date date)
Creates the date.
|
static Date |
createDate(long timeInMillis)
Creates the date.
|
static GregorianCalendar |
createGregorianCalendar(Calendar calendar)
Creates the gregorian calendar.
|
static GregorianCalendar |
createGregorianCalendar(Date date)
Creates the gregorian calendar.
|
static GregorianCalendar |
createGregorianCalendar(long timeInMillis)
Creates the gregorian calendar.
|
static GregorianCalendar |
createGregorianCalendar(long timeInMillis,
TimeZone tz)
Creates the gregorian calendar.
|
static Date |
createJUDate(Calendar calendar)
Creates the JU date.
|
static Date |
createJUDate(Date date)
Creates the JU date.
|
static Date |
createJUDate(long timeInMillis)
Creates the JU date.
|
static Time |
createTime(Calendar calendar)
Creates the time.
|
static Time |
createTime(Date date)
Creates the time.
|
static Time |
createTime(long timeInMillis)
Creates the time.
|
static Timestamp |
createTimestamp(Calendar calendar)
Creates the timestamp.
|
static Timestamp |
createTimestamp(Date date)
Creates the timestamp.
|
static Timestamp |
createTimestamp(long timeInMillis)
Creates the timestamp.
|
static XMLGregorianCalendar |
createXMLGregorianCalendar(Calendar calendar)
Creates the XML gregorian calendar.
|
static XMLGregorianCalendar |
createXMLGregorianCalendar(Date date)
Creates the XML gregorian calendar.
|
static XMLGregorianCalendar |
createXMLGregorianCalendar(long timeInMillis)
Creates the XML gregorian calendar.
|
static 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 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 GregorianCalendar |
currentGregorianCalendar()
Current gregorian calendar.
|
static 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 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 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 XMLGregorianCalendar |
currentXMLGregorianCalendar()
Current XML gregorian calendar.
|
static String |
format(Calendar c) |
static String |
format(Calendar c,
String format) |
static String |
format(Calendar c,
String format,
TimeZone timeZone) |
static String |
format(Date date) |
static String |
format(Date date,
String format) |
static String |
format(Date date,
String format,
TimeZone timeZone) |
static void |
format(Writer writer,
Calendar c) |
static void |
format(Writer writer,
Calendar c,
String format) |
static void |
format(Writer writer,
Calendar c,
String format,
TimeZone timeZone) |
static void |
format(Writer writer,
Date date) |
static void |
format(Writer writer,
Date date,
String format) |
static void |
format(Writer writer,
Date date,
String format,
TimeZone timeZone) |
static void |
format(Writer writer,
XMLGregorianCalendar c) |
static void |
format(Writer writer,
XMLGregorianCalendar c,
String format) |
static void |
format(Writer writer,
XMLGregorianCalendar c,
String format,
TimeZone timeZone) |
static String |
format(XMLGregorianCalendar c) |
static String |
format(XMLGregorianCalendar c,
String format) |
static String |
format(XMLGregorianCalendar c,
String format,
TimeZone timeZone) |
static Calendar |
parseCalendar(String calendar)
Parses the calendar.
|
static Calendar |
parseCalendar(String calendar,
String format)
Parses the calendar.
|
static Calendar |
parseCalendar(String calendar,
String format,
TimeZone timeZone)
Converts the specified
calendar with the specified format to a new instance of Calendar. |
static Date |
parseDate(String date)
Parses the date.
|
static Date |
parseDate(String date,
String format)
Parses the date.
|
static Date |
parseDate(String date,
String format,
TimeZone timeZone)
Converts the specified
date with the specified format to a new instance of java.sql.Date. |
static GregorianCalendar |
parseGregorianCalendar(String calendar)
Parses the gregorian calendar.
|
static GregorianCalendar |
parseGregorianCalendar(String calendar,
String format)
Parses the gregorian calendar.
|
static GregorianCalendar |
parseGregorianCalendar(String calendar,
String format,
TimeZone timeZone)
Converts the specified
calendar with the specified format to a new instance of GregorianCalendar. |
static Date |
parseJUDate(String date)
Parses the JU date.
|
static Date |
parseJUDate(String date,
String format)
Parses the JU date.
|
static Date |
parseJUDate(String date,
String format,
TimeZone timeZone)
Converts the specified
date with the specified format to a new instance of java.util.Date. |
static Time |
parseTime(String date)
Parses the time.
|
static Time |
parseTime(String date,
String format)
Parses the time.
|
static Time |
parseTime(String date,
String format,
TimeZone timeZone)
Converts the specified
date with the specified format to a new instance of Time. |
static Timestamp |
parseTimestamp(String date)
Parses the timestamp.
|
static Timestamp |
parseTimestamp(String date,
String format)
Parses the timestamp.
|
static Timestamp |
parseTimestamp(String date,
String format,
TimeZone timeZone)
Converts the specified
date with the specified format to a new instance of Timestamp. |
static XMLGregorianCalendar |
parseXMLGregorianCalendar(String calendar)
Parses the XML gregorian calendar.
|
static XMLGregorianCalendar |
parseXMLGregorianCalendar(String calendar,
String format)
Parses the XML gregorian calendar.
|
static XMLGregorianCalendar |
parseXMLGregorianCalendar(String calendar,
String format,
TimeZone timeZone)
Converts the specified
calendar with the specified format to a new instance of XMLGregorianCalendar. |
static <T extends Calendar> |
roll(T calendar,
long amount,
CalendarUnit unit)
Deprecated.
replaced by
addYears/addMonths/addWeeks/... |
static <T extends Date> |
roll(T date,
long amount,
CalendarUnit unit)
Deprecated.
replaced by
addYears/addMonths/addWeeks/... |
static <T extends Calendar> |
roll(T calendar,
long amount,
TimeUnit unit)
Deprecated.
replaced by
addYears/addMonths/addWeeks/... |
static <T extends Date> |
roll(T date,
long amount,
TimeUnit unit)
Deprecated.
replaced by
addYears/addMonths/addWeeks/... |
static <T extends Calendar> |
round(T calendar,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends Date> |
round(T date,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends Date> |
setDays(T date,
int amount)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends Date> |
setHours(T date,
int amount)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends Date> |
setMilliseconds(T date,
int amount)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends Date> |
setMinutes(T date,
int amount)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends Date> |
setMonths(T date,
int amount)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends Date> |
setSeconds(T date,
int amount)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends Date> |
setYears(T date,
int amount)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends Calendar> |
truncate(T calendar,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static <T extends Date> |
truncate(T date,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static int |
truncatedCompareTo(Calendar cal1,
Calendar cal2,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static int |
truncatedCompareTo(Date date1,
Date date2,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static boolean |
truncatedEquals(Calendar cal1,
Calendar cal2,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
static boolean |
truncatedEquals(Date date1,
Date date2,
int field)
Copied from Apache Commons Lang under Apache License v2.
|
public static final TimeZone UTC_TIME_ZONE
public static final TimeZone LOCAL_TIME_ZONE
public static final String LOCAL_YEAR_FORMAT
public static final String LOCAL_MONTH_DAY_FORMAT
public static final String LOCAL_DATE_FORMAT
public static final String LOCAL_TIME_FORMAT
public static final String LOCAL_DATETIME_FORMAT
public static final String LOCAL_TIMESTAMP_FORMAT
public static final String ISO_8601_DATETIME_FORMAT
public static final String ISO_8601_TIMESTAMP_FORMAT
public static final String RFC1123_DATE_FORMAT
public static final int SEMI_MONTH
public static Time currentTime()
java.sql.Time
returned is based on the
current time in the default time zone with the default locale.public static Date currentDate()
java.sql.Date
returned is based on the
current time in the default time zone with the default locale.public static Timestamp currentTimestamp()
java.sql.Timestamp
returned is based on
the current time in the default time zone with the default locale.public static Date currentJUDate()
java.util.Date
returned is based on the
current time in the default time zone with the default locale.public static Calendar currentCalendar()
java.util.Calendar
returned is based on
the current time in the default time zone with the default locale.public static GregorianCalendar currentGregorianCalendar()
public static XMLGregorianCalendar currentXMLGregorianCalendar()
public static Date createJUDate(Calendar calendar)
calendar
- public static Date createJUDate(Date date)
date
- public static Date createJUDate(long timeInMillis)
timeInMillis
- public static Date createDate(Calendar calendar)
calendar
- public static Date createDate(long timeInMillis)
timeInMillis
- public static Time createTime(Calendar calendar)
calendar
- public static Time createTime(long timeInMillis)
timeInMillis
- public static Timestamp createTimestamp(Calendar calendar)
calendar
- public static Timestamp createTimestamp(Date date)
date
- public static Timestamp createTimestamp(long timeInMillis)
timeInMillis
- public static Calendar createCalendar(Calendar calendar)
calendar
- public static Calendar createCalendar(Date date)
date
- public static Calendar createCalendar(long timeInMillis)
timeInMillis
- public static Calendar createCalendar(long timeInMillis, TimeZone tz)
timeInMillis
- tz
- public static GregorianCalendar createGregorianCalendar(Calendar calendar)
calendar
- public static GregorianCalendar createGregorianCalendar(Date date)
date
- public static GregorianCalendar createGregorianCalendar(long timeInMillis)
timeInMillis
- public static GregorianCalendar createGregorianCalendar(long timeInMillis, TimeZone tz)
timeInMillis
- tz
- public static XMLGregorianCalendar createXMLGregorianCalendar(Calendar calendar)
calendar
- public static XMLGregorianCalendar createXMLGregorianCalendar(Date date)
date
- public static XMLGregorianCalendar createXMLGregorianCalendar(long timeInMillis)
timeInMillis
- public static Date parseJUDate(String date)
date
- public static Date parseJUDate(String date, String format)
date
- format
- public static Date parseJUDate(String date, String format, 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
- timeZone
- IllegalArgumentException
- if the date given can't be parsed with specified format.public static Date parseDate(String date, String format)
date
- format
- public static Date parseDate(String date, String format, 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 Time parseTime(String date, String format)
date
- format
- public static Time parseTime(String date, String format, 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 Timestamp parseTimestamp(String date)
date
- public static Timestamp parseTimestamp(String date, String format)
date
- format
- public static Timestamp parseTimestamp(String date, String format, 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 Calendar parseCalendar(String calendar)
calendar
- public static Calendar parseCalendar(String calendar, String format)
calendar
- format
- public static Calendar parseCalendar(String calendar, String format, 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 GregorianCalendar parseGregorianCalendar(String calendar)
calendar
- public static GregorianCalendar parseGregorianCalendar(String calendar, String format)
calendar
- format
- public static GregorianCalendar parseGregorianCalendar(String calendar, String format, 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 XMLGregorianCalendar parseXMLGregorianCalendar(String calendar)
calendar
- public static XMLGregorianCalendar parseXMLGregorianCalendar(String calendar, String format)
calendar
- format
- public static XMLGregorianCalendar parseXMLGregorianCalendar(String calendar, String format, 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 String format(Date date, String format, TimeZone timeZone)
date
- format
- timeZone
- public static void format(Writer writer, Date date, String format)
writer
- date
- format
- public static void format(Writer writer, Date date, String format, TimeZone timeZone)
writer
- date
- format
- timeZone
- public static String format(Calendar c, String format, TimeZone timeZone)
c
- format
- timeZone
- public static void format(Writer writer, Calendar c, String format)
writer
- c
- format
- public static void format(Writer writer, Calendar c, String format, TimeZone timeZone)
writer
- c
- format
- timeZone
- public static String format(XMLGregorianCalendar c)
c
- public static String format(XMLGregorianCalendar c, String format)
c
- format
- public static String format(XMLGregorianCalendar c, String format, TimeZone timeZone)
c
- format
- timeZone
- public static void format(Writer writer, XMLGregorianCalendar c)
writer
- c
- public static void format(Writer writer, XMLGregorianCalendar c, String format)
writer
- c
- format
- public static void format(Writer writer, XMLGregorianCalendar c, String format, TimeZone timeZone)
writer
- c
- format
- timeZone
- public static <T extends Date> T setYears(T date, int amount)
Date
is unchanged.T
- date
- the date, not nullamount
- the amount to setDate
set with the specified valueIllegalArgumentException
- if the date is nullpublic static <T extends Date> T setMonths(T date, int amount)
Date
is unchanged.T
- date
- the date, not nullamount
- the amount to setDate
set with the specified valueIllegalArgumentException
- if the date is nullpublic static <T extends Date> T setDays(T date, int amount)
Date
is unchanged.T
- date
- the date, not nullamount
- the amount to setDate
set with the specified valueIllegalArgumentException
- if the date is nullpublic static <T extends Date> T setHours(T date, int amount)
Date
is unchanged.T
- date
- the date, not nullamount
- the amount to setDate
set with the specified valueIllegalArgumentException
- if the date is nullpublic static <T extends Date> T setMinutes(T date, int amount)
Date
is unchanged.T
- date
- the date, not nullamount
- the amount to setDate
set with the specified valueIllegalArgumentException
- if the date is nullpublic static <T extends Date> T setSeconds(T date, int amount)
Date
is unchanged.T
- date
- the date, not nullamount
- the amount to setDate
set with the specified valueIllegalArgumentException
- if the date is nullpublic static <T extends Date> T setMilliseconds(T date, int amount)
Date
is unchanged.T
- date
- the date, not nullamount
- the amount to setDate
set with the specified valueIllegalArgumentException
- if the date is null@Deprecated public static <T extends Date> T roll(T date, long amount, TimeUnit unit)
addYears/addMonths/addWeeks/...
N.roll(date, -5, TimeUnit.DAYS)
.
T
- date
- amount
- unit
- @Deprecated public static <T extends Date> T roll(T date, long amount, CalendarUnit unit)
addYears/addMonths/addWeeks/...
N.roll(date, -5, CalendarUnit.DAY)
.
T
- date
- amount
- unit
- @Deprecated public static <T extends Calendar> T roll(T calendar, long amount, TimeUnit unit)
addYears/addMonths/addWeeks/...
N.roll(c, -5, TimeUnit.DAYS)
.
T
- calendar
- amount
- unit
- @Deprecated public static <T extends Calendar> T roll(T calendar, long amount, CalendarUnit unit)
addYears/addMonths/addWeeks/...
N.roll(c, -5, CalendarUnit.DAY)
.
T
- calendar
- amount
- unit
- public static <T extends Date> T addYears(T date, int amount)
Date
is unchanged.T
- date
- the date, not nullamount
- the amount to add, may be negativeIllegalArgumentException
- if the date is nullpublic static <T extends Date> T addMonths(T date, int amount)
Date
is unchanged.T
- date
- the date, not nullamount
- the amount to add, may be negativeIllegalArgumentException
- if the date is nullpublic static <T extends Date> T addWeeks(T date, int amount)
Date
is unchanged.T
- date
- the date, not nullamount
- the amount to add, may be negativeIllegalArgumentException
- if the date is nullpublic static <T extends Date> T addDays(T date, int amount)
Date
is unchanged.T
- date
- the date, not nullamount
- the amount to add, may be negativeIllegalArgumentException
- if the date is nullpublic static <T extends Date> T addHours(T date, int amount)
Date
is unchanged.T
- date
- the date, not nullamount
- the amount to add, may be negativeIllegalArgumentException
- if the date is nullpublic static <T extends Date> T addMinutes(T date, int amount)
Date
is unchanged.T
- date
- the date, not nullamount
- the amount to add, may be negativeIllegalArgumentException
- if the date is nullpublic static <T extends Date> T addSeconds(T date, int amount)
Date
is unchanged.T
- date
- the date, not nullamount
- the amount to add, may be negativeIllegalArgumentException
- if the date is nullpublic static <T extends Date> T addMilliseconds(T date, int amount)
Date
is unchanged.T
- date
- the date, not nullamount
- the amount to add, may be negativeIllegalArgumentException
- if the date is nullpublic static <T extends Calendar> T addYears(T calendar, int amount)
Date
is unchanged.T
- calendar
- the calendar, not nullamount
- the amount to add, may be negativeIllegalArgumentException
- if the calendar is nullpublic static <T extends Calendar> T addMonths(T calendar, int amount)
Date
is unchanged.T
- calendar
- the calendar, not nullamount
- the amount to add, may be negativeIllegalArgumentException
- if the calendar is nullpublic static <T extends Calendar> T addWeeks(T calendar, int amount)
Date
is unchanged.T
- calendar
- the calendar, not nullamount
- the amount to add, may be negativeIllegalArgumentException
- if the calendar is nullpublic static <T extends Calendar> T addDays(T calendar, int amount)
Date
is unchanged.T
- calendar
- the calendar, not nullamount
- the amount to add, may be negativeIllegalArgumentException
- if the calendar is nullpublic static <T extends Calendar> T addHours(T calendar, int amount)
Date
is unchanged.T
- calendar
- the calendar, not nullamount
- the amount to add, may be negativeIllegalArgumentException
- if the calendar is nullpublic static <T extends Calendar> T addMinutes(T calendar, int amount)
Date
is unchanged.T
- calendar
- the calendar, not nullamount
- the amount to add, may be negativeIllegalArgumentException
- if the calendar is nullpublic static <T extends Calendar> T addSeconds(T calendar, int amount)
Date
is unchanged.T
- calendar
- the calendar, not nullamount
- the amount to add, may be negativeIllegalArgumentException
- if the calendar is nullpublic static <T extends Calendar> T addMilliseconds(T calendar, int amount)
Date
is unchanged.T
- calendar
- the calendar, not nullamount
- the amount to add, may be negativeIllegalArgumentException
- if the calendar is nullpublic static <T extends 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:
T
- date
- the date to work with, not nullfield
- the field from Calendar
or SEMI_MONTH
ArithmeticException
- if the year is over 280 millionpublic static <T extends 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:
T
- calendar
- the date to work with, not nullfield
- the field from Calendar
or SEMI_MONTH
IllegalArgumentException
- if the date is null
ArithmeticException
- if the year is over 280 millionpublic static <T extends 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.
T
- date
- the date to work with, not nullfield
- the field from Calendar
or SEMI_MONTH
IllegalArgumentException
- if the date is null
ArithmeticException
- if the year is over 280 millionpublic static <T extends 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.
T
- calendar
- the date to work with, not nullfield
- the field from Calendar
or SEMI_MONTH
IllegalArgumentException
- if the date is null
ArithmeticException
- if the year is over 280 millionpublic static <T extends 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.
T
- date
- the date to work with, not nullfield
- the field from Calendar
or SEMI_MONTH
IllegalArgumentException
- if the date is null
ArithmeticException
- if the year is over 280 millionpublic static <T extends 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.
T
- calendar
- the date to work with, not nullfield
- the field from Calendar
or SEMI_MONTH
IllegalArgumentException
- if the date is null
ArithmeticException
- if the year is over 280 millionpublic static boolean truncatedEquals(Calendar cal1, 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
IllegalArgumentException
- if any argument is null
truncate(Calendar, int)
,
truncatedEquals(Date, Date, int)
public static boolean truncatedEquals(Date date1, 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
IllegalArgumentException
- if any argument is null
truncate(Date, int)
,
truncatedEquals(Calendar, Calendar, int)
public static int truncatedCompareTo(Calendar cal1, Calendar cal2, int field)
cal1
- the first calendar, not null
cal2
- the second calendar, not null
field
- the field from Calendar
IllegalArgumentException
- if any argument is null
truncate(Calendar, int)
,
truncatedCompareTo(Date, Date, int)
public static int truncatedCompareTo(Date date1, Date date2, int field)
date1
- the first date, not null
date2
- the second date, not null
field
- the field from Calendar
IllegalArgumentException
- if any argument is null
truncate(Calendar, int)
,
truncatedCompareTo(Date, Date, int)
Copyright © 2020. All rights reserved.