Class DateUtil
- Direct Known Subclasses:
DateUtil.Dates
,DateUtil.DateTimeUtil
,DateUtil.Times
Note: This class includes codes copied from Apache Commons Lang, Google Guava and other open source projects under the Apache License 2.0. The methods copied from other libraries/frameworks/projects may be modified in this class.
- Since:
- 1.2.6
- Author:
- Haiyang Li
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
The Class Dates.static final class
The Class DateTimeUtil.static final class
The Class Times. -
Field Summary
FieldsModifier 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 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 <T extends Date>
Tceiling
(T date, CalendarField field) 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 Calendar
currentCalendarRolled
(long amount, TimeUnit unit) Adds or subtracts the specified amount of time with the given time unit to currentjava.util.Calendar
.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 Date
currentDateRolled
(long amount, TimeUnit unit) Adds or subtracts the specified amount of time with the given time unit to currentjava.sql.Date
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 Date
currentJUDateRolled
(long amount, TimeUnit unit) Adds or subtracts the specified amount of time with the given time unit to currentjava.util.Date
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 long
static Time
currentTimeRolled
(long amount, TimeUnit unit) Adds or subtracts the specified amount of time with the given time unit to currentjava.sql.Time
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 Timestamp
currentTimestampRolled
(long amount, TimeUnit unit) Adds or subtracts the specified amount of time with the given time unit to currentjava.sql.Timestamp
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
Format specifieddate
with formatyyyy-MM-dd'T'HH:mm:ss.SSS'Z'
if it's aTimestamp
, otherwise format it with formatyyyy-MM-dd'T'HH:mm:ss'Z'
.static String
static String
static String
static String
format
(XMLGregorianCalendar c, String format) static String
format
(XMLGregorianCalendar c, String format, TimeZone timeZone) static String
Format current date with format with specifiedyyyy-MM-dd'T'HH:mm:ss'Z'
.static String
Format current date with format with specifiedyyyy-MM-dd'T'HH:mm:ss.SSS'Z'
.static String
Format current date with formatyyyy-MM-dd
.static String
Format current date with format with specifiedyyyy-MM-dd HH:mm:ss
.static long
getFragmentInDays
(Calendar calendar, CalendarField fragment) Copied from Apache Commons Lang under Apache License v2.static long
getFragmentInDays
(Date date, CalendarField fragment) Copied from Apache Commons Lang under Apache License v2.static long
getFragmentInHours
(Calendar calendar, CalendarField fragment) Copied from Apache Commons Lang under Apache License v2.static long
getFragmentInHours
(Date date, CalendarField fragment) Copied from Apache Commons Lang under Apache License v2.static long
getFragmentInMilliseconds
(Calendar calendar, CalendarField fragment) Copied from Apache Commons Lang under Apache License v2.static long
getFragmentInMilliseconds
(Date date, CalendarField fragment) Copied from Apache Commons Lang under Apache License v2.static long
getFragmentInMinutes
(Calendar calendar, CalendarField fragment) Copied from Apache Commons Lang under Apache License v2.static long
getFragmentInMinutes
(Date date, CalendarField fragment) Copied from Apache Commons Lang under Apache License v2.static long
getFragmentInSeconds
(Calendar calendar, CalendarField fragment) Copied from Apache Commons Lang under Apache License v2.static long
getFragmentInSeconds
(Date date, CalendarField fragment) Copied from Apache Commons Lang under Apache License v2.static int
getLastDateOfMonth
(Date date) static int
getLastDateOfYear
(Date date) static boolean
isLastDateOfMonth
(Date date) static boolean
isLastDateOfYear
(Date date) static boolean
Copied from Apache Commons Lang under Apache License v2.static boolean
Copied from Apache Commons Lang under Apache License v2.static boolean
isSameInstant
(Calendar cal1, Calendar cal2) Copied from Apache Commons Lang under Apache License v2.static boolean
isSameInstant
(Date date1, Date date2) Copied from Apache Commons Lang under Apache License v2.static boolean
isSameLocalTime
(Calendar cal1, Calendar cal2) Copied from Apache Commons Lang under Apache License v2.static boolean
isSameMonth
(Calendar cal1, Calendar cal2) static boolean
isSameMonth
(Date date1, Date date2) static boolean
isSameYear
(Calendar cal1, Calendar cal2) static boolean
isSameYear
(Date date1, Date date2) 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, CalendarField 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>
Tround
(T date, CalendarField field) 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 <T extends Date>
Ttruncate
(T date, CalendarField field) static int
truncatedCompareTo
(Calendar cal1, Calendar cal2, int field) Copied from Apache Commons Lang under Apache License v2.static int
truncatedCompareTo
(Calendar cal1, Calendar cal2, CalendarField field) static int
truncatedCompareTo
(Date date1, Date date2, int field) Copied from Apache Commons Lang under Apache License v2.static int
truncatedCompareTo
(Date date1, Date date2, CalendarField field) static boolean
truncatedEquals
(Calendar cal1, Calendar cal2, int field) Copied from Apache Commons Lang under Apache License v2.static boolean
truncatedEquals
(Calendar cal1, Calendar cal2, CalendarField field) static boolean
truncatedEquals
(Date date1, Date date2, int field) Copied from Apache Commons Lang under Apache License v2.static boolean
truncatedEquals
(Date date1, Date date2, CalendarField field)
-
Field Details
-
UTC_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
-
currentTimeMillis
- Returns:
- See Also:
-
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:
-
currentTimeRolled
Adds or subtracts the specified amount of time with the given time unit to currentjava.sql.Time
- Parameters:
amount
-unit
-- Returns:
- a new
Time
by Adding or subtracting the specified amount of time to currentjava.sql.Time
.
-
currentDateRolled
Adds or subtracts the specified amount of time with the given time unit to currentjava.sql.Date
- Parameters:
amount
-unit
-- Returns:
- a new
Date
by Adding or subtracting the specified amount of time to currentjava.sql.Date
.
-
currentTimestampRolled
Adds or subtracts the specified amount of time with the given time unit to currentjava.sql.Timestamp
- Parameters:
amount
-unit
-- Returns:
- a new
Timestamp
by Adding or subtracting the specified amount of time to currentjava.sql.Timestamp
.
-
currentJUDateRolled
Adds or subtracts the specified amount of time with the given time unit to currentjava.util.Date
- Parameters:
amount
-unit
-- Returns:
- a new
Date
by Adding or subtracting the specified amount of time to currentjava.util.Date
.
-
currentCalendarRolled
Adds or subtracts the specified amount of time with the given time unit to currentjava.util.Calendar
.- Parameters:
amount
-unit
-- Returns:
- a new
Calendar
by Adding or subtracting the specified amount of time to currentjava.util.Calendar
.
-
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:
null
if(Strings.isEmpty(date) || (date.length() == 4 && "null".equalsIgnoreCase(date)))
. (auto-generated java doc for return)- 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:
null
if(Strings.isEmpty(date) || (date.length() == 4 && "null".equalsIgnoreCase(date)))
. (auto-generated java doc for return)
-
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:
null
if(Strings.isEmpty(date) || (date.length() == 4 && "null".equalsIgnoreCase(date)))
. (auto-generated java doc for return)
-
parseTimestamp
Parses the timestamp.- Parameters:
date
-- Returns:
-
parseTimestamp
Parses the timestamp.- Parameters:
date
-format
-- Returns:
-
parseTimestamp
@MayReturnNull public static Timestamp parseTimestamp(String date, String format, TimeZone timeZone) 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:
null
if(Strings.isEmpty(date) || (date.length() == 4 && "null".equalsIgnoreCase(date)))
. (auto-generated java doc for return)
-
parseCalendar
Parses the calendar.- Parameters:
calendar
-- Returns:
-
parseCalendar
Parses the calendar.- Parameters:
calendar
-format
-- Returns:
-
parseCalendar
@MayReturnNull @Beta public static Calendar parseCalendar(String calendar, String format, TimeZone timeZone) 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:
null
if(Strings.isEmpty(calendar) || (calendar.length() == 4 && "null".equalsIgnoreCase(calendar)))
. (auto-generated java doc for return)
-
parseGregorianCalendar
Parses the gregorian calendar.- Parameters:
calendar
-- Returns:
-
parseGregorianCalendar
Parses the gregorian calendar.- Parameters:
calendar
-format
-- Returns:
-
parseGregorianCalendar
@MayReturnNull @Beta 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:
null
if(Strings.isEmpty(calendar) || (calendar.length() == 4 && "null".equalsIgnoreCase(calendar)))
. (auto-generated java doc for return)
-
parseXMLGregorianCalendar
Parses the XML gregorian calendar.- Parameters:
calendar
-- Returns:
-
parseXMLGregorianCalendar
Parses the XML gregorian calendar.- Parameters:
calendar
-format
-- Returns:
-
parseXMLGregorianCalendar
@MayReturnNull @Beta 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:
null
if(Strings.isEmpty(calendar) || (calendar.length() == 4 && "null".equalsIgnoreCase(calendar)))
. (auto-generated java doc for return)
-
formatLocalDate
Format current date with formatyyyy-MM-dd
.- Returns:
-
formatLocalDateTime
Format current date with format with specifiedyyyy-MM-dd HH:mm:ss
.- Returns:
-
formatCurrentDateTime
Format current date with format with specifiedyyyy-MM-dd'T'HH:mm:ss'Z'
.- Returns:
-
formatCurrentTimestamp
Format current date with format with specifiedyyyy-MM-dd'T'HH:mm:ss.SSS'Z'
.- Returns:
-
format
Format specifieddate
with formatyyyy-MM-dd'T'HH:mm:ss.SSS'Z'
if it's aTimestamp
, otherwise format it with formatyyyy-MM-dd'T'HH:mm:ss'Z'
.- 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
- Type Parameters:
T
-- Parameters:
date
-field
-- Returns:
-
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
-
round
- Type Parameters:
T
-- Parameters:
calendar
-field
-- Returns:
-
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
- Type Parameters:
T
-- Parameters:
date
-field
-- Returns:
-
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
-
truncate
- Type Parameters:
T
-- Parameters:
calendar
-field
-- Returns:
-
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
- Type Parameters:
T
-- Parameters:
date
-field
-- Returns:
-
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
-
ceiling
- Type Parameters:
T
-- Parameters:
calendar
-field
-- Returns:
-
truncatedEquals
- Parameters:
cal1
-cal2
-field
-- Returns:
- See Also:
-
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
- Parameters:
date1
-date2
-field
-- Returns:
- 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:
-
truncatedCompareTo
- Parameters:
cal1
-cal2
-field
-- Returns:
- See Also:
-
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
- Parameters:
date1
-date2
-field
-- Returns:
- 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:
-
getFragmentInMilliseconds
Copied from Apache Commons Lang under Apache License v2.
Returns the number of milliseconds within the fragment. All datefields greater than the fragment will be ignored.
Asking the milliseconds of any date will only return the number of milliseconds of the current second (resulting in a number between 0 and 999). This method will retrieve the number of milliseconds for any fragment. For example, if you want to calculate the number of milliseconds past today, your fragment is Calendar.DATE or Calendar.DAY_OF_YEAR. The result will be all milliseconds of the past hour(s), minutes(s) and second(s).
Valid fragments are: Calendar.YEAR, Calendar.MONTH, both Calendar.DAY_OF_YEAR and Calendar.DATE, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND and Calendar.MILLISECOND A fragment less than or equal to a SECOND field will return 0.
- January 1, 2008 7:15:10.538 with Calendar.SECOND as fragment will return 538
- January 6, 2008 7:15:10.538 with Calendar.SECOND as fragment will return 538
- January 6, 2008 7:15:10.538 with Calendar.MINUTE as fragment will return 10538 (10*1000 + 538)
- January 16, 2008 7:15:10.538 with Calendar.MILLISECOND as fragment will return 0 (a millisecond cannot be split in milliseconds)
- Parameters:
date
- the date to work with, not nullfragment
- theCalendar
field part of date to calculate- Returns:
- number of milliseconds within the fragment of date
- Throws:
IllegalArgumentException
- if the date isnull
or fragment is not supported- Since:
- 2.4
-
getFragmentInSeconds
Copied from Apache Commons Lang under Apache License v2.
Returns the number of seconds within the fragment. All datefields greater than the fragment will be ignored.
Asking the seconds of any date will only return the number of seconds of the current minute (resulting in a number between 0 and 59). This method will retrieve the number of seconds for any fragment. For example, if you want to calculate the number of seconds past today, your fragment is Calendar.DATE or Calendar.DAY_OF_YEAR. The result will be all seconds of the past hour(s) and minutes(s).
Valid fragments are: Calendar.YEAR, Calendar.MONTH, both Calendar.DAY_OF_YEAR and Calendar.DATE, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND and Calendar.MILLISECOND A fragment less than or equal to a SECOND field will return 0.
- January 1, 2008 7:15:10.538 with Calendar.MINUTE as fragment will return 10 (equivalent to deprecated date.getSeconds())
- January 6, 2008 7:15:10.538 with Calendar.MINUTE as fragment will return 10 (equivalent to deprecated date.getSeconds())
- January 6, 2008 7:15:10.538 with Calendar.DAY_OF_YEAR as fragment will return 26110 (7*3600 + 15*60 + 10)
- January 16, 2008 7:15:10.538 with Calendar.MILLISECOND as fragment will return 0 (a millisecond cannot be split in seconds)
- Parameters:
date
- the date to work with, not nullfragment
- theCalendar
field part of date to calculate- Returns:
- number of seconds within the fragment of date
- Throws:
IllegalArgumentException
- if the date isnull
or fragment is not supported- Since:
- 2.4
-
getFragmentInMinutes
Copied from Apache Commons Lang under Apache License v2.
Returns the number of minutes within the fragment. All datefields greater than the fragment will be ignored.
Asking the minutes of any date will only return the number of minutes of the current hour (resulting in a number between 0 and 59). This method will retrieve the number of minutes for any fragment. For example, if you want to calculate the number of minutes past this month, your fragment is Calendar.MONTH. The result will be all minutes of the past day(s) and hour(s).
Valid fragments are: Calendar.YEAR, Calendar.MONTH, both Calendar.DAY_OF_YEAR and Calendar.DATE, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND and Calendar.MILLISECOND A fragment less than or equal to a MINUTE field will return 0.
- January 1, 2008 7:15:10.538 with Calendar.HOUR_OF_DAY as fragment will return 15 (equivalent to deprecated date.getMinutes())
- January 6, 2008 7:15:10.538 with Calendar.HOUR_OF_DAY as fragment will return 15 (equivalent to deprecated date.getMinutes())
- January 1, 2008 7:15:10.538 with Calendar.MONTH as fragment will return 15
- January 6, 2008 7:15:10.538 with Calendar.MONTH as fragment will return 435 (7*60 + 15)
- January 16, 2008 7:15:10.538 with Calendar.MILLISECOND as fragment will return 0 (a millisecond cannot be split in minutes)
- Parameters:
date
- the date to work with, not nullfragment
- theCalendar
field part of date to calculate- Returns:
- number of minutes within the fragment of date
- Throws:
IllegalArgumentException
- if the date isnull
or fragment is not supported- Since:
- 2.4
-
getFragmentInHours
Copied from Apache Commons Lang under Apache License v2.
Returns the number of hours within the fragment. All datefields greater than the fragment will be ignored.
Asking the hours of any date will only return the number of hours of the current day (resulting in a number between 0 and 23). This method will retrieve the number of hours for any fragment. For example, if you want to calculate the number of hours past this month, your fragment is Calendar.MONTH. The result will be all hours of the past day(s).
Valid fragments are: Calendar.YEAR, Calendar.MONTH, both Calendar.DAY_OF_YEAR and Calendar.DATE, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND and Calendar.MILLISECOND A fragment less than or equal to a HOUR field will return 0.
- January 1, 2008 7:15:10.538 with Calendar.DAY_OF_YEAR as fragment will return 7 (equivalent to deprecated date.getHours())
- January 6, 2008 7:15:10.538 with Calendar.DAY_OF_YEAR as fragment will return 7 (equivalent to deprecated date.getHours())
- January 1, 2008 7:15:10.538 with Calendar.MONTH as fragment will return 7
- January 6, 2008 7:15:10.538 with Calendar.MONTH as fragment will return 127 (5*24 + 7)
- January 16, 2008 7:15:10.538 with Calendar.MILLISECOND as fragment will return 0 (a millisecond cannot be split in hours)
- Parameters:
date
- the date to work with, not nullfragment
- theCalendar
field part of date to calculate- Returns:
- number of hours within the fragment of date
- Throws:
IllegalArgumentException
- if the date isnull
or fragment is not supported- Since:
- 2.4
-
getFragmentInDays
Copied from Apache Commons Lang under Apache License v2.
Returns the number of days within the fragment. All datefields greater than the fragment will be ignored.
Asking the days of any date will only return the number of days of the current month (resulting in a number between 1 and 31). This method will retrieve the number of days for any fragment. For example, if you want to calculate the number of days past this year, your fragment is Calendar.YEAR. The result will be all days of the past month(s).
Valid fragments are: Calendar.YEAR, Calendar.MONTH, both Calendar.DAY_OF_YEAR and Calendar.DATE, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND and Calendar.MILLISECOND A fragment less than or equal to a DAY field will return 0.
- January 28, 2008 with Calendar.MONTH as fragment will return 28 (equivalent to deprecated date.getDay())
- February 28, 2008 with Calendar.MONTH as fragment will return 28 (equivalent to deprecated date.getDay())
- January 28, 2008 with Calendar.YEAR as fragment will return 28
- February 28, 2008 with Calendar.YEAR as fragment will return 59
- January 28, 2008 with Calendar.MILLISECOND as fragment will return 0 (a millisecond cannot be split in days)
- Parameters:
date
- the date to work with, not nullfragment
- theCalendar
field part of date to calculate- Returns:
- number of days within the fragment of date
- Throws:
IllegalArgumentException
- if the date isnull
or fragment is not supported- Since:
- 2.4
-
getFragmentInMilliseconds
Copied from Apache Commons Lang under Apache License v2.
Returns the number of milliseconds within the fragment. All datefields greater than the fragment will be ignored.
Asking the milliseconds of any date will only return the number of milliseconds of the current second (resulting in a number between 0 and 999). This method will retrieve the number of milliseconds for any fragment. For example, if you want to calculate the number of seconds past today, your fragment is Calendar.DATE or Calendar.DAY_OF_YEAR. The result will be all seconds of the past hour(s), minutes(s) and second(s).
Valid fragments are: Calendar.YEAR, Calendar.MONTH, both Calendar.DAY_OF_YEAR and Calendar.DATE, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND and Calendar.MILLISECOND A fragment less than or equal to a MILLISECOND field will return 0.
- January 1, 2008 7:15:10.538 with Calendar.SECOND as fragment will return 538 (equivalent to calendar.get(Calendar.MILLISECOND))
- January 6, 2008 7:15:10.538 with Calendar.SECOND as fragment will return 538 (equivalent to calendar.get(Calendar.MILLISECOND))
- January 6, 2008 7:15:10.538 with Calendar.MINUTE as fragment will return 10538 (10*1000 + 538)
- January 16, 2008 7:15:10.538 with Calendar.MILLISECOND as fragment will return 0 (a millisecond cannot be split in milliseconds)
- Parameters:
calendar
- the calendar to work with, not nullfragment
- theCalendar
field part of calendar to calculate- Returns:
- number of milliseconds within the fragment of date
- Throws:
IllegalArgumentException
- if the date isnull
or fragment is not supported- Since:
- 2.4
-
getFragmentInSeconds
Copied from Apache Commons Lang under Apache License v2.
Returns the number of seconds within the fragment. All datefields greater than the fragment will be ignored.
Asking the seconds of any date will only return the number of seconds of the current minute (resulting in a number between 0 and 59). This method will retrieve the number of seconds for any fragment. For example, if you want to calculate the number of seconds past today, your fragment is Calendar.DATE or Calendar.DAY_OF_YEAR. The result will be all seconds of the past hour(s) and minutes(s).
Valid fragments are: Calendar.YEAR, Calendar.MONTH, both Calendar.DAY_OF_YEAR and Calendar.DATE, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND and Calendar.MILLISECOND A fragment less than or equal to a SECOND field will return 0.
- January 1, 2008 7:15:10.538 with Calendar.MINUTE as fragment will return 10 (equivalent to calendar.get(Calendar.SECOND))
- January 6, 2008 7:15:10.538 with Calendar.MINUTE as fragment will return 10 (equivalent to calendar.get(Calendar.SECOND))
- January 6, 2008 7:15:10.538 with Calendar.DAY_OF_YEAR as fragment will return 26110 (7*3600 + 15*60 + 10)
- January 16, 2008 7:15:10.538 with Calendar.MILLISECOND as fragment will return 0 (a millisecond cannot be split in seconds)
- Parameters:
calendar
- the calendar to work with, not nullfragment
- theCalendar
field part of calendar to calculate- Returns:
- number of seconds within the fragment of date
- Throws:
IllegalArgumentException
- if the date isnull
or fragment is not supported- Since:
- 2.4
-
getFragmentInMinutes
Copied from Apache Commons Lang under Apache License v2.
Returns the number of minutes within the fragment. All datefields greater than the fragment will be ignored.
Asking the minutes of any date will only return the number of minutes of the current hour (resulting in a number between 0 and 59). This method will retrieve the number of minutes for any fragment. For example, if you want to calculate the number of minutes past this month, your fragment is Calendar.MONTH. The result will be all minutes of the past day(s) and hour(s).
Valid fragments are: Calendar.YEAR, Calendar.MONTH, both Calendar.DAY_OF_YEAR and Calendar.DATE, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND and Calendar.MILLISECOND A fragment less than or equal to a MINUTE field will return 0.
- January 1, 2008 7:15:10.538 with Calendar.HOUR_OF_DAY as fragment will return 15 (equivalent to calendar.get(Calendar.MINUTES))
- January 6, 2008 7:15:10.538 with Calendar.HOUR_OF_DAY as fragment will return 15 (equivalent to calendar.get(Calendar.MINUTES))
- January 1, 2008 7:15:10.538 with Calendar.MONTH as fragment will return 15
- January 6, 2008 7:15:10.538 with Calendar.MONTH as fragment will return 435 (7*60 + 15)
- January 16, 2008 7:15:10.538 with Calendar.MILLISECOND as fragment will return 0 (a millisecond cannot be split in minutes)
- Parameters:
calendar
- the calendar to work with, not nullfragment
- theCalendar
field part of calendar to calculate- Returns:
- number of minutes within the fragment of date
- Throws:
IllegalArgumentException
- if the date isnull
or fragment is not supported- Since:
- 2.4
-
getFragmentInHours
Copied from Apache Commons Lang under Apache License v2.
Returns the number of hours within the fragment. All datefields greater than the fragment will be ignored.
Asking the hours of any date will only return the number of hours of the current day (resulting in a number between 0 and 23). This method will retrieve the number of hours for any fragment. For example, if you want to calculate the number of hours past this month, your fragment is Calendar.MONTH. The result will be all hours of the past day(s).
Valid fragments are: Calendar.YEAR, Calendar.MONTH, both Calendar.DAY_OF_YEAR and Calendar.DATE, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND and Calendar.MILLISECOND A fragment less than or equal to a HOUR field will return 0.
- January 1, 2008 7:15:10.538 with Calendar.DAY_OF_YEAR as fragment will return 7 (equivalent to calendar.get(Calendar.HOUR_OF_DAY))
- January 6, 2008 7:15:10.538 with Calendar.DAY_OF_YEAR as fragment will return 7 (equivalent to calendar.get(Calendar.HOUR_OF_DAY))
- January 1, 2008 7:15:10.538 with Calendar.MONTH as fragment will return 7
- January 6, 2008 7:15:10.538 with Calendar.MONTH as fragment will return 127 (5*24 + 7)
- January 16, 2008 7:15:10.538 with Calendar.MILLISECOND as fragment will return 0 (a millisecond cannot be split in hours)
- Parameters:
calendar
- the calendar to work with, not nullfragment
- theCalendar
field part of calendar to calculate- Returns:
- number of hours within the fragment of date
- Throws:
IllegalArgumentException
- if the date isnull
or fragment is not supported- Since:
- 2.4
-
getFragmentInDays
Copied from Apache Commons Lang under Apache License v2.
Returns the number of days within the fragment. All datefields greater than the fragment will be ignored.
Asking the days of any date will only return the number of days of the current month (resulting in a number between 1 and 31). This method will retrieve the number of days for any fragment. For example, if you want to calculate the number of days past this year, your fragment is Calendar.YEAR. The result will be all days of the past month(s).
Valid fragments are: Calendar.YEAR, Calendar.MONTH, both Calendar.DAY_OF_YEAR and Calendar.DATE, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND and Calendar.MILLISECOND A fragment less than or equal to a DAY field will return 0.
- January 28, 2008 with Calendar.MONTH as fragment will return 28 (equivalent to calendar.get(Calendar.DAY_OF_MONTH))
- February 28, 2008 with Calendar.MONTH as fragment will return 28 (equivalent to calendar.get(Calendar.DAY_OF_MONTH))
- January 28, 2008 with Calendar.YEAR as fragment will return 28 (equivalent to calendar.get(Calendar.DAY_OF_YEAR))
- February 28, 2008 with Calendar.YEAR as fragment will return 59 (equivalent to calendar.get(Calendar.DAY_OF_YEAR))
- January 28, 2008 with Calendar.MILLISECOND as fragment will return 0 (a millisecond cannot be split in days)
- Parameters:
calendar
- the calendar to work with, not nullfragment
- theCalendar
field part of calendar to calculate- Returns:
- number of days within the fragment of date
- Throws:
IllegalArgumentException
- if the date isnull
or fragment is not supported- Since:
- 2.4
-
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
-
isSameMonth
- Parameters:
date1
-date2
-- Returns:
-
isSameMonth
- Parameters:
cal1
-cal2
-- Returns:
-
isSameYear
- Parameters:
date1
-date2
-- Returns:
-
isSameYear
- Parameters:
cal1
-cal2
-- Returns:
-
isSameInstant
Copied from Apache Commons Lang under Apache License v2.
Checks if two date objects represent the same instant in time.
This method compares the long millisecond time of the two objects.
- Parameters:
date1
- the first date, not altered, not nulldate2
- the second date, not altered, not null- Returns:
- true if they represent the same millisecond instant
- Throws:
IllegalArgumentException
- if either date isnull
- Since:
- 2.1
-
isSameInstant
Copied from Apache Commons Lang under Apache License v2.
Checks if two calendar objects represent the same instant in time.
This method compares the long millisecond time of the two objects.
- Parameters:
cal1
- the first calendar, not altered, not nullcal2
- the second calendar, not altered, not null- Returns:
- true if they represent the same millisecond instant
- Throws:
IllegalArgumentException
- if either date isnull
- Since:
- 2.1
-
isSameLocalTime
Copied from Apache Commons Lang under Apache License v2.
Checks if two calendar objects represent the same local time.
This method compares the values of the fields of the two objects. In addition, both calendars must be the same of the same type.
- Parameters:
cal1
- the first calendar, not altered, not nullcal2
- the second calendar, not altered, not null- Returns:
- true if they represent the same millisecond instant
- Throws:
IllegalArgumentException
- if either date isnull
- Since:
- 2.1
-
isLastDateOfMonth
- Parameters:
date
-- Returns:
-
isLastDateOfYear
- Parameters:
date
-- Returns:
-
getLastDateOfMonth
- Parameters:
date
-- Returns:
-
getLastDateOfYear
- Parameters:
date
-- Returns:
-
addYears/addMonths/addWeeks/...