Class DateUtil
- Direct Known Subclasses:
DateUtil.DateTimeUtil
- Since:
- 1.2.6
- Author:
- Haiyang Li
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
It's default date/time format.static final String
It's default timestamp format.static final String
static final String
static final String
static final String
static final TimeZone
static final String
static final String
Date format.static final String
This constant defines the date format specified by RFC 1123 / RFC 822.static final int
This is half a month, so this represents whether a date is in the top or bottom half of the month.static final TimeZone
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Date>
TaddDays
(T date, int amount) Adds a number of days to a date returning a new object.static <T extends Date>
TaddHours
(T date, int amount) Adds a number of hours to a date returning a new object.static <T extends Date>
TaddMilliseconds
(T date, int amount) Adds a number of milliseconds to a date returning a new object.static <T extends Date>
TaddMinutes
(T date, int amount) Adds a number of minutes to a date returning a new object.static <T extends Date>
TaddMonths
(T date, int amount) Adds a number of months to a date returning a new object.static <T extends Date>
TaddSeconds
(T date, int amount) Adds a number of seconds to a date returning a new object.static <T extends Date>
TaddWeeks
(T date, int amount) Adds a number of weeks to a date returning a new object.static <T extends Date>
TaddYears
(T date, int amount) Adds a number of years to a date returning a new object.static <T extends Date>
Tceiling
(T date, int field) Copied from Apache Commons Lang under Apache License v2.static Calendar
createCalendar
(long timeInMillis) Creates the calendar.static Calendar
createCalendar
(long timeInMillis, TimeZone tz) Creates the calendar.static Calendar
createCalendar
(Calendar calendar) Creates the calendar.static Calendar
createCalendar
(Date date) Creates the calendar.static Date
createDate
(long timeInMillis) Creates the date.static Date
createDate
(Calendar calendar) Creates the date.static Date
createDate
(Date date) Creates the date.static GregorianCalendar
createGregorianCalendar
(long timeInMillis) Creates the gregorian calendar.static GregorianCalendar
createGregorianCalendar
(long timeInMillis, TimeZone tz) Creates the gregorian calendar.static GregorianCalendar
createGregorianCalendar
(Calendar calendar) Creates the gregorian calendar.static GregorianCalendar
createGregorianCalendar
(Date date) Creates the gregorian calendar.static Date
createJUDate
(long timeInMillis) Creates the JU date.static Date
createJUDate
(Calendar calendar) Creates the JU date.static Date
createJUDate
(Date date) Creates the JU date.static Time
createTime
(long timeInMillis) Creates the time.static Time
createTime
(Calendar calendar) Creates the time.static Time
createTime
(Date date) Creates the time.static Timestamp
createTimestamp
(long timeInMillis) Creates the timestamp.static Timestamp
createTimestamp
(Calendar calendar) Creates the timestamp.static Timestamp
createTimestamp
(Date date) Creates the timestamp.static XMLGregorianCalendar
createXMLGregorianCalendar
(long timeInMillis) Creates the XML gregorian calendar.static XMLGregorianCalendar
createXMLGregorianCalendar
(Calendar calendar) Creates the XML gregorian calendar.static XMLGregorianCalendar
Creates the XML gregorian calendar.static Calendar
A new instance ofjava.util.Calendar
returned is based on the current time in the default time zone with the default locale.static Date
A new instance ofjava.sql.Date
returned is based on the current time in the default time zone with the default locale.static GregorianCalendar
Current gregorian calendar.static Date
A new instance ofjava.util.Date
returned is based on the current time in the default time zone with the default locale.static Time
A new instance ofjava.sql.Time
returned is based on the current time in the default time zone with the default locale.static Timestamp
A new instance ofjava.sql.Timestamp
returned is based on the current time in the default time zone with the default locale.static XMLGregorianCalendar
Current XML gregorian calendar.static void
static void
static void
static void
static void
static void
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
static String
static String
static String
static String
static String
static String
static String
format
(XMLGregorianCalendar c, String format) static String
format
(XMLGregorianCalendar c, String format, TimeZone timeZone) static boolean
Copied from Apache Commons Lang under Apache License v2.static boolean
Copied from Apache Commons Lang under Apache License v2.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 specifiedcalendar
with the specifiedformat
to a new instance of Calendar.static Date
Parses the date.static Date
Parses the date.static Date
Converts the specifieddate
with the specifiedformat
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 specifiedcalendar
with the specifiedformat
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 specifieddate
with the specifiedformat
to a new instance of java.util.Date.static Time
Parses the time.static Time
Parses the time.static Time
Converts the specifieddate
with the specifiedformat
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 specifieddate
with the specifiedformat
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 specifiedcalendar
with the specifiedformat
to a new instance of XMLGregorianCalendar.static <T extends Date>
Troll
(T date, long amount, CalendarUnit unit) Deprecated.static <T extends Date>
TDeprecated.replaced byaddYears/addMonths/addWeeks/...
static <T extends Date>
Tround
(T date, int field) Copied from Apache Commons Lang under Apache License v2.static <T extends Date>
TsetDays
(T date, int amount) Copied from Apache Commons Lang under Apache License v2.static <T extends Date>
TsetHours
(T date, int amount) Copied from Apache Commons Lang under Apache License v2.static <T extends Date>
TsetMilliseconds
(T date, int amount) Copied from Apache Commons Lang under Apache License v2.static <T extends Date>
TsetMinutes
(T date, int amount) Copied from Apache Commons Lang under Apache License v2.static <T extends Date>
TsetMonths
(T date, int amount) Copied from Apache Commons Lang under Apache License v2.static <T extends Date>
TsetSeconds
(T date, int amount) Copied from Apache Commons Lang under Apache License v2.static <T extends Date>
TsetYears
(T date, int amount) Copied from Apache Commons Lang under Apache License v2.static <T extends Date>
Ttruncate
(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.
-
Field Details
-
UTC_TIME_ZONE
-
LOCAL_TIME_ZONE
-
LOCAL_YEAR_FORMAT
Date format.- See Also:
-
LOCAL_MONTH_DAY_FORMAT
- See Also:
-
LOCAL_DATE_FORMAT
- See Also:
-
LOCAL_TIME_FORMAT
- See Also:
-
LOCAL_DATETIME_FORMAT
- See Also:
-
LOCAL_TIMESTAMP_FORMAT
- See Also:
-
ISO_8601_DATETIME_FORMAT
It's default date/time format.- See Also:
-
ISO_8601_TIMESTAMP_FORMAT
It's default timestamp format.- See Also:
-
RFC1123_DATE_FORMAT
This constant defines the date format specified by RFC 1123 / RFC 822. Used for parsing via `SimpleDateFormat` as well as error messages.- See Also:
-
SEMI_MONTH
public static final int SEMI_MONTHThis is half a month, so this represents whether a date is in the top or bottom half of the month.- See Also:
-
-
Method Details
-
currentTime
A new instance ofjava.sql.Time
returned is based on the current time in the default time zone with the default locale.- Returns:
-
currentDate
A new instance ofjava.sql.Date
returned is based on the current time in the default time zone with the default locale.- Returns:
-
currentTimestamp
A new instance ofjava.sql.Timestamp
returned is based on the current time in the default time zone with the default locale.- Returns:
-
currentJUDate
A new instance ofjava.util.Date
returned is based on the current time in the default time zone with the default locale.- Returns:
-
currentCalendar
A new instance ofjava.util.Calendar
returned is based on the current time in the default time zone with the default locale.- Returns:
- a Calendar.
-
currentGregorianCalendar
Current gregorian calendar.- Returns:
-
currentXMLGregorianCalendar
Current XML gregorian calendar.- Returns:
-
createJUDate
Creates the JU date.- Parameters:
calendar
-- Returns:
-
createJUDate
Creates the JU date.- Parameters:
date
-- Returns:
-
createJUDate
Creates the JU date.- Parameters:
timeInMillis
-- Returns:
-
createDate
Creates the date.- Parameters:
calendar
-- Returns:
-
createDate
Creates the date.- Parameters:
date
-- Returns:
-
createDate
Creates the date.- Parameters:
timeInMillis
-- Returns:
-
createTime
Creates the time.- Parameters:
calendar
-- Returns:
-
createTime
Creates the time.- Parameters:
date
-- Returns:
-
createTime
Creates the time.- Parameters:
timeInMillis
-- Returns:
-
createTimestamp
Creates the timestamp.- Parameters:
calendar
-- Returns:
-
createTimestamp
Creates the timestamp.- Parameters:
date
-- Returns:
-
createTimestamp
Creates the timestamp.- Parameters:
timeInMillis
-- Returns:
-
createCalendar
Creates the calendar.- Parameters:
calendar
-- Returns:
-
createCalendar
Creates the calendar.- Parameters:
date
-- Returns:
-
createCalendar
Creates the calendar.- Parameters:
timeInMillis
-- Returns:
-
createCalendar
Creates the calendar.- Parameters:
timeInMillis
-tz
-- Returns:
-
createGregorianCalendar
Creates the gregorian calendar.- Parameters:
calendar
-- Returns:
-
createGregorianCalendar
Creates the gregorian calendar.- Parameters:
date
-- Returns:
-
createGregorianCalendar
Creates the gregorian calendar.- Parameters:
timeInMillis
-- Returns:
-
createGregorianCalendar
Creates the gregorian calendar.- Parameters:
timeInMillis
-tz
-- Returns:
-
createXMLGregorianCalendar
Creates the XML gregorian calendar.- Parameters:
calendar
-- Returns:
-
createXMLGregorianCalendar
Creates the XML gregorian calendar.- Parameters:
date
-- Returns:
-
createXMLGregorianCalendar
Creates the XML gregorian calendar.- Parameters:
timeInMillis
-- Returns:
-
parseJUDate
Parses the JU date.- Parameters:
date
-- Returns:
-
parseJUDate
Parses the JU date.- Parameters:
date
-format
-- Returns:
-
parseJUDate
Converts the specifieddate
with the specifiedformat
to a new instance of java.util.Date.null
is returned if the specifieddate
is null or empty.- Parameters:
date
-format
-timeZone
-- Returns:
- Throws:
IllegalArgumentException
- if the date given can't be parsed with specified format.
-
parseDate
Parses the date.- Parameters:
date
-- Returns:
-
parseDate
Parses the date.- Parameters:
date
-format
-- Returns:
-
parseDate
Converts the specifieddate
with the specifiedformat
to a new instance of java.sql.Date.null
is returned if the specifieddate
is null or empty.- Parameters:
date
-format
-timeZone
-- Returns:
-
parseTime
Parses the time.- Parameters:
date
-- Returns:
-
parseTime
Parses the time.- Parameters:
date
-format
-- Returns:
-
parseTime
Converts the specifieddate
with the specifiedformat
to a new instance of Time.null
is returned if the specifieddate
is null or empty.- Parameters:
date
-format
-timeZone
-- Returns:
-
parseTimestamp
Parses the timestamp.- Parameters:
date
-- Returns:
-
parseTimestamp
Parses the timestamp.- Parameters:
date
-format
-- Returns:
-
parseTimestamp
Converts the specifieddate
with the specifiedformat
to a new instance of Timestamp.null
is returned if the specifieddate
is null or empty.- Parameters:
date
-format
-timeZone
-- Returns:
-
parseCalendar
Parses the calendar.- Parameters:
calendar
-- Returns:
-
parseCalendar
Parses the calendar.- Parameters:
calendar
-format
-- Returns:
-
parseCalendar
Converts the specifiedcalendar
with the specifiedformat
to a new instance of Calendar.null
is returned if the specifieddate
is null or empty.- Parameters:
calendar
-format
-timeZone
-- Returns:
-
parseGregorianCalendar
Parses the gregorian calendar.- Parameters:
calendar
-- Returns:
-
parseGregorianCalendar
Parses the gregorian calendar.- Parameters:
calendar
-format
-- Returns:
-
parseGregorianCalendar
public static GregorianCalendar parseGregorianCalendar(String calendar, String format, TimeZone timeZone) Converts the specifiedcalendar
with the specifiedformat
to a new instance of GregorianCalendar.null
is returned if the specifieddate
is null or empty.- Parameters:
calendar
-format
-timeZone
-- Returns:
-
parseXMLGregorianCalendar
Parses the XML gregorian calendar.- Parameters:
calendar
-- Returns:
-
parseXMLGregorianCalendar
Parses the XML gregorian calendar.- Parameters:
calendar
-format
-- Returns:
-
parseXMLGregorianCalendar
public static XMLGregorianCalendar parseXMLGregorianCalendar(String calendar, String format, TimeZone timeZone) Converts the specifiedcalendar
with the specifiedformat
to a new instance of XMLGregorianCalendar.null
is returned if the specifieddate
is null or empty.- Parameters:
calendar
-format
-timeZone
-- Returns:
-
format
- Parameters:
date
-- Returns:
-
format
- Parameters:
date
-format
-- Returns:
-
format
- Parameters:
date
-format
-timeZone
-- Returns:
-
format
- Parameters:
writer
-date
-
-
format
- Parameters:
writer
-date
-format
-
-
format
- Parameters:
writer
-date
-format
-timeZone
-
-
format
- Parameters:
c
-- Returns:
-
format
- Parameters:
c
-format
-- Returns:
-
format
- Parameters:
c
-format
-timeZone
-- Returns:
-
format
- Parameters:
writer
-c
-
-
format
- Parameters:
writer
-c
-format
-
-
format
- Parameters:
writer
-c
-format
-timeZone
-
-
format
- Parameters:
c
-- Returns:
-
format
- Parameters:
c
-format
-- Returns:
-
format
- Parameters:
c
-format
-timeZone
-- Returns:
-
format
- Parameters:
writer
-c
-
-
format
- Parameters:
writer
-c
-format
-
-
format
- Parameters:
writer
-c
-format
-timeZone
-
-
setYears
Copied from Apache Commons Lang under Apache License v2.
Sets the years field to a date returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
date
- the date, not nullamount
- the amount to set- Returns:
- a new
Date
set with the specified value - Throws:
IllegalArgumentException
- if the date is null- Since:
- 2.4
-
setMonths
Copied from Apache Commons Lang under Apache License v2.
Sets the months field to a date returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
date
- the date, not nullamount
- the amount to set- Returns:
- a new
Date
set with the specified value - Throws:
IllegalArgumentException
- if the date is null- Since:
- 2.4
-
setDays
Copied from Apache Commons Lang under Apache License v2.
Sets the day of month field to a date returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
date
- the date, not nullamount
- the amount to set- Returns:
- a new
Date
set with the specified value - Throws:
IllegalArgumentException
- if the date is null- Since:
- 2.4
-
setHours
Copied from Apache Commons Lang under Apache License v2.
Sets the hours field to a date returning a new object. Hours range from 0-23. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
date
- the date, not nullamount
- the amount to set- Returns:
- a new
Date
set with the specified value - Throws:
IllegalArgumentException
- if the date is null- Since:
- 2.4
-
setMinutes
Copied from Apache Commons Lang under Apache License v2.
Sets the minute field to a date returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
date
- the date, not nullamount
- the amount to set- Returns:
- a new
Date
set with the specified value - Throws:
IllegalArgumentException
- if the date is null- Since:
- 2.4
-
setSeconds
Copied from Apache Commons Lang under Apache License v2.
Sets the seconds field to a date returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
date
- the date, not nullamount
- the amount to set- Returns:
- a new
Date
set with the specified value - Throws:
IllegalArgumentException
- if the date is null- Since:
- 2.4
-
setMilliseconds
Copied from Apache Commons Lang under Apache License v2.
Sets the milliseconds field to a date returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
date
- the date, not nullamount
- the amount to set- Returns:
- a new
Date
set with the specified value - Throws:
IllegalArgumentException
- if the date is null- Since:
- 2.4
-
roll
Deprecated.replaced byaddYears/addMonths/addWeeks/...
Adds or subtracts the specified amount of time to the given time unit, based on the calendar's rules. For example, to subtract 5 days from the current time of the calendar, you can achieve it by calling:N.roll(date, -5, TimeUnit.DAYS)
.- Type Parameters:
T
-- Parameters:
date
-amount
-unit
-- Returns:
- a new instance of Date with the specified amount rolled.
-
roll
Deprecated.replaced byaddYears/addMonths/addWeeks/...
Adds or subtracts the specified amount of time to the given calendar unit, based on the calendar's rules. For example, to subtract 5 days from the current time of the calendar, you can achieve it by calling:N.roll(date, -5, CalendarUnit.DAY)
.- Type Parameters:
T
-- Parameters:
date
-amount
-unit
-- Returns:
- a new instance of Date with the specified amount rolled.
-
roll
Deprecated.replaced byaddYears/addMonths/addWeeks/...
Adds or subtracts the specified amount of time to the given time unit, based on the calendar's rules. For example, to subtract 5 days from the current time of the calendar, you can achieve it by calling:N.roll(c, -5, TimeUnit.DAYS)
.- Type Parameters:
T
-- Parameters:
calendar
-amount
-unit
-- Returns:
- a new instance of Calendar with the specified amount rolled.
-
roll
Deprecated.replaced byaddYears/addMonths/addWeeks/...
Adds or subtracts the specified amount of time to the given calendar unit, based on the calendar's rules. For example, to subtract 5 days from the current time of the calendar, you can achieve it by calling:N.roll(c, -5, CalendarUnit.DAY)
.- Type Parameters:
T
-- Parameters:
calendar
-amount
-unit
-- Returns:
- a new instance of Calendar with the specified amount rolled.
-
addYears
Adds a number of years to a date returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
date
- the date, not nullamount
- the amount to add, may be negative- Returns:
- Throws:
IllegalArgumentException
- if the date is null
-
addMonths
Adds a number of months to a date returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
date
- the date, not nullamount
- the amount to add, may be negative- Returns:
- Throws:
IllegalArgumentException
- if the date is null
-
addWeeks
Adds a number of weeks to a date returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
date
- the date, not nullamount
- the amount to add, may be negative- Returns:
- Throws:
IllegalArgumentException
- if the date is null
-
addDays
Adds a number of days to a date returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
date
- the date, not nullamount
- the amount to add, may be negative- Returns:
- Throws:
IllegalArgumentException
- if the date is null
-
addHours
Adds a number of hours to a date returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
date
- the date, not nullamount
- the amount to add, may be negative- Returns:
- Throws:
IllegalArgumentException
- if the date is null
-
addMinutes
Adds a number of minutes to a date returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
date
- the date, not nullamount
- the amount to add, may be negative- Returns:
- Throws:
IllegalArgumentException
- if the date is null
-
addSeconds
Adds a number of seconds to a date returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
date
- the date, not nullamount
- the amount to add, may be negative- Returns:
- Throws:
IllegalArgumentException
- if the date is null
-
addMilliseconds
Adds a number of milliseconds to a date returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
date
- the date, not nullamount
- the amount to add, may be negative- Returns:
- Throws:
IllegalArgumentException
- if the date is null
-
addYears
Adds a number of years to a calendar returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
calendar
- the calendar, not nullamount
- the amount to add, may be negative- Returns:
- Throws:
IllegalArgumentException
- if the calendar is null
-
addMonths
Adds a number of months to a calendar returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
calendar
- the calendar, not nullamount
- the amount to add, may be negative- Returns:
- Throws:
IllegalArgumentException
- if the calendar is null
-
addWeeks
Adds a number of weeks to a calendar returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
calendar
- the calendar, not nullamount
- the amount to add, may be negative- Returns:
- Throws:
IllegalArgumentException
- if the calendar is null
-
addDays
Adds a number of days to a calendar returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
calendar
- the calendar, not nullamount
- the amount to add, may be negative- Returns:
- Throws:
IllegalArgumentException
- if the calendar is null
-
addHours
Adds a number of hours to a calendar returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
calendar
- the calendar, not nullamount
- the amount to add, may be negative- Returns:
- Throws:
IllegalArgumentException
- if the calendar is null
-
addMinutes
Adds a number of minutes to a calendar returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
calendar
- the calendar, not nullamount
- the amount to add, may be negative- Returns:
- Throws:
IllegalArgumentException
- if the calendar is null
-
addSeconds
Adds a number of seconds to a calendar returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
calendar
- the calendar, not nullamount
- the amount to add, may be negative- Returns:
- Throws:
IllegalArgumentException
- if the calendar is null
-
addMilliseconds
Adds a number of milliseconds to a calendar returning a new object. The originalDate
is unchanged.- Type Parameters:
T
-- Parameters:
calendar
- the calendar, not nullamount
- the amount to add, may be negative- Returns:
- Throws:
IllegalArgumentException
- if the calendar is null
-
round
Copied from Apache Commons Lang under Apache License v2.
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:
- March 30, 2003 01:10 rounds to March 30, 2003 01:00
- March 30, 2003 01:40 rounds to March 30, 2003 03:00
- March 30, 2003 02:10 rounds to March 30, 2003 03:00
- March 30, 2003 02:40 rounds to March 30, 2003 04:00
- Type Parameters:
T
-- Parameters:
date
- the date to work with, not nullfield
- the field fromCalendar
orSEMI_MONTH
- Returns:
- Throws:
ArithmeticException
- if the year is over 280 million
-
round
Copied from Apache Commons Lang under Apache License v2.
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:
- March 30, 2003 01:10 rounds to March 30, 2003 01:00
- March 30, 2003 01:40 rounds to March 30, 2003 03:00
- March 30, 2003 02:10 rounds to March 30, 2003 03:00
- March 30, 2003 02:40 rounds to March 30, 2003 04:00
- Type Parameters:
T
-- Parameters:
calendar
- the date to work with, not nullfield
- the field fromCalendar
orSEMI_MONTH
- Returns:
- Throws:
IllegalArgumentException
- if the date isnull
ArithmeticException
- if the year is over 280 million
-
truncate
Copied from Apache Commons Lang under Apache License v2.
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.
- Type Parameters:
T
-- Parameters:
date
- the date to work with, not nullfield
- the field fromCalendar
orSEMI_MONTH
- Returns:
- Throws:
IllegalArgumentException
- if the date isnull
ArithmeticException
- if the year is over 280 million
-
truncate
Copied from Apache Commons Lang under Apache License v2.
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.
- Type Parameters:
T
-- Parameters:
calendar
- the date to work with, not nullfield
- the field fromCalendar
orSEMI_MONTH
- Returns:
- Throws:
IllegalArgumentException
- if the date isnull
ArithmeticException
- if the year is over 280 million
-
ceiling
Copied from Apache Commons Lang under Apache License v2.
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.
- Type Parameters:
T
-- Parameters:
date
- the date to work with, not nullfield
- the field fromCalendar
orSEMI_MONTH
- Returns:
- Throws:
IllegalArgumentException
- if the date isnull
ArithmeticException
- if the year is over 280 million- Since:
- 2.5
-
ceiling
Copied from Apache Commons Lang under Apache License v2.
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.
- Type Parameters:
T
-- Parameters:
calendar
- the date to work with, not nullfield
- the field fromCalendar
orSEMI_MONTH
- Returns:
- Throws:
IllegalArgumentException
- if the date isnull
ArithmeticException
- if the year is over 280 million- Since:
- 2.5
-
truncatedEquals
Copied from Apache Commons Lang under Apache License v2.
Determines if two calendars are equal up to no more than the specified most significant field.- Parameters:
cal1
- the first calendar, notnull
cal2
- the second calendar, notnull
field
- the field fromCalendar
- Returns:
true
if equal; otherwisefalse
- Throws:
IllegalArgumentException
- if any argument isnull
- Since:
- 3.0
- See Also:
-
truncatedEquals
Copied from Apache Commons Lang under Apache License v2.
Determines if two dates are equal up to no more than the specified most significant field.- Parameters:
date1
- the first date, notnull
date2
- the second date, notnull
field
- the field fromCalendar
- Returns:
true
if equal; otherwisefalse
- Throws:
IllegalArgumentException
- if any argument isnull
- Since:
- 3.0
- See Also:
-
#truncate(Date, int)
truncatedEquals(Calendar, Calendar, int)
-
truncatedCompareTo
Copied from Apache Commons Lang under Apache License v2.
Determines how two calendars compare up to no more than the specified most significant field.- Parameters:
cal1
- the first calendar, notnull
cal2
- the second calendar, notnull
field
- the field fromCalendar
- Returns:
- a negative integer, zero, or a positive integer as the first calendar is less than, equal to, or greater than the second.
- Throws:
IllegalArgumentException
- if any argument isnull
- Since:
- 3.0
- See Also:
-
truncatedCompareTo
Copied from Apache Commons Lang under Apache License v2.
Determines how two dates compare up to no more than the specified most significant field.- Parameters:
date1
- the first date, notnull
date2
- the second date, notnull
field
- the field fromCalendar
- Returns:
- a negative integer, zero, or a positive integer as the first date is less than, equal to, or greater than the second.
- Throws:
IllegalArgumentException
- if any argument isnull
- Since:
- 3.0
- See Also:
-
isSameDay
Copied from Apache Commons Lang under Apache License v2.
Checks if two date objects are on the same day ignoring time.
28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true. 28 Mar 2002 13:45 and 12 Mar 2002 13:45 would return false.
- Parameters:
date1
- the first date, not altered, not nulldate2
- the second date, not altered, not null- Returns:
- true if they represent the same day
- Throws:
IllegalArgumentException
- if either date isnull
- Since:
- 2.1
-
isSameDay
Copied from Apache Commons Lang under Apache License v2.
Checks if two calendar objects are on the same day ignoring time.
28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true. 28 Mar 2002 13:45 and 12 Mar 2002 13:45 would return false.
- Parameters:
cal1
- the first calendar, not altered, not nullcal2
- the second calendar, not altered, not null- Returns:
- true if they represent the same day
- Throws:
IllegalArgumentException
- if either calendar isnull
- Since:
- 2.1
-
addYears/addMonths/addWeeks/...