Class DateUtil

java.lang.Object
com.landawn.abacus.util.DateUtil
Direct Known Subclasses:
DateUtil.DateTimeUtil, DateUtil.Times

public abstract class DateUtil extends Object

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
  • Field Details

    • UTC_TIME_ZONE

      public static final TimeZone UTC_TIME_ZONE
    • LOCAL_YEAR_FORMAT

      public static final String LOCAL_YEAR_FORMAT
      Date format.
      See Also:
    • LOCAL_MONTH_DAY_FORMAT

      public static final String LOCAL_MONTH_DAY_FORMAT
      See Also:
    • LOCAL_DATE_FORMAT

      public static final String LOCAL_DATE_FORMAT
      See Also:
    • LOCAL_TIME_FORMAT

      public static final String LOCAL_TIME_FORMAT
      See Also:
    • LOCAL_DATETIME_FORMAT

      public static final String LOCAL_DATETIME_FORMAT
      See Also:
    • LOCAL_TIMESTAMP_FORMAT

      public static final String LOCAL_TIMESTAMP_FORMAT
      See Also:
    • ISO_8601_DATETIME_FORMAT

      public static final String ISO_8601_DATETIME_FORMAT
      It's default date/time format.
      See Also:
    • ISO_8601_TIMESTAMP_FORMAT

      public static final String ISO_8601_TIMESTAMP_FORMAT
      It's default timestamp format.
      See Also:
    • RFC1123_DATE_FORMAT

      public static final String 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_MONTH
      This 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

      @Beta public static long currentTimeMillis()
      Returns:
      See Also:
    • currentTime

      public 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.
      Returns:
    • currentDate

      public 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.
      Returns:
    • currentTimestamp

      public 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.
      Returns:
    • currentJUDate

      public 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.
      Returns:
    • currentCalendar

      public 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.
      Returns:
      a Calendar.
    • currentGregorianCalendar

      public static GregorianCalendar currentGregorianCalendar()
      Current gregorian calendar.
      Returns:
    • currentXMLGregorianCalendar

      public static XMLGregorianCalendar currentXMLGregorianCalendar()
      Current XML gregorian calendar.
      Returns:
    • currentTimeRolled

      @Beta public static Time currentTimeRolled(long amount, TimeUnit unit)
      Adds or subtracts the specified amount of time with the given time unit to current java.sql.Time
      Parameters:
      amount -
      unit -
      Returns:
    • currentDateRolled

      @Beta public static Date currentDateRolled(long amount, TimeUnit unit)
      Adds or subtracts the specified amount of time with the given time unit to current java.sql.Date
      Parameters:
      amount -
      unit -
      Returns:
      a new Date by Adding or subtracting the specified amount of time to current java.sql.Date.
    • currentTimestampRolled

      @Beta public static Timestamp currentTimestampRolled(long amount, TimeUnit unit)
      Adds or subtracts the specified amount of time with the given time unit to current java.sql.Timestamp
      Parameters:
      amount -
      unit -
      Returns:
    • currentJUDateRolled

      @Beta public static Date currentJUDateRolled(long amount, TimeUnit unit)
      Adds or subtracts the specified amount of time with the given time unit to current java.util.Date
      Parameters:
      amount -
      unit -
      Returns:
      a new Date by Adding or subtracting the specified amount of time to current java.util.Date.
    • currentCalendarRolled

      @Beta public static Calendar currentCalendarRolled(long amount, TimeUnit unit)
      Adds or subtracts the specified amount of time with the given time unit to current java.util.Calendar.
      Parameters:
      amount -
      unit -
      Returns:
      a new Calendar by Adding or subtracting the specified amount of time to current java.util.Calendar.
    • createJUDate

      public static Date createJUDate(Calendar calendar)
      Creates the JU date.
      Parameters:
      calendar -
      Returns:
    • createJUDate

      public static Date createJUDate(Date date)
      Creates the JU date.
      Parameters:
      date -
      Returns:
    • createJUDate

      public static Date createJUDate(long timeInMillis)
      Creates the JU date.
      Parameters:
      timeInMillis -
      Returns:
    • createDate

      public static Date createDate(Calendar calendar)
      Creates the date.
      Parameters:
      calendar -
      Returns:
    • createDate

      public static Date createDate(Date date)
      Creates the date.
      Parameters:
      date -
      Returns:
    • createDate

      public static Date createDate(long timeInMillis)
      Creates the date.
      Parameters:
      timeInMillis -
      Returns:
    • createTime

      public static Time createTime(Calendar calendar)
      Creates the time.
      Parameters:
      calendar -
      Returns:
    • createTime

      public static Time createTime(Date date)
      Creates the time.
      Parameters:
      date -
      Returns:
    • createTime

      public static Time createTime(long timeInMillis)
      Creates the time.
      Parameters:
      timeInMillis -
      Returns:
    • createTimestamp

      public static Timestamp createTimestamp(Calendar calendar)
      Creates the timestamp.
      Parameters:
      calendar -
      Returns:
    • createTimestamp

      public static Timestamp createTimestamp(Date date)
      Creates the timestamp.
      Parameters:
      date -
      Returns:
    • createTimestamp

      public static Timestamp createTimestamp(long timeInMillis)
      Creates the timestamp.
      Parameters:
      timeInMillis -
      Returns:
    • createCalendar

      public static Calendar createCalendar(Calendar calendar)
      Creates the calendar.
      Parameters:
      calendar -
      Returns:
    • createCalendar

      public static Calendar createCalendar(Date date)
      Creates the calendar.
      Parameters:
      date -
      Returns:
    • createCalendar

      public static Calendar createCalendar(long timeInMillis)
      Creates the calendar.
      Parameters:
      timeInMillis -
      Returns:
    • createCalendar

      public static Calendar createCalendar(long timeInMillis, TimeZone tz)
      Creates the calendar.
      Parameters:
      timeInMillis -
      tz -
      Returns:
    • createGregorianCalendar

      public static GregorianCalendar createGregorianCalendar(Calendar calendar)
      Creates the gregorian calendar.
      Parameters:
      calendar -
      Returns:
    • createGregorianCalendar

      public static GregorianCalendar createGregorianCalendar(Date date)
      Creates the gregorian calendar.
      Parameters:
      date -
      Returns:
    • createGregorianCalendar

      public static GregorianCalendar createGregorianCalendar(long timeInMillis)
      Creates the gregorian calendar.
      Parameters:
      timeInMillis -
      Returns:
    • createGregorianCalendar

      public static GregorianCalendar createGregorianCalendar(long timeInMillis, TimeZone tz)
      Creates the gregorian calendar.
      Parameters:
      timeInMillis -
      tz -
      Returns:
    • createXMLGregorianCalendar

      public static XMLGregorianCalendar createXMLGregorianCalendar(Calendar calendar)
      Creates the XML gregorian calendar.
      Parameters:
      calendar -
      Returns:
    • createXMLGregorianCalendar

      public static XMLGregorianCalendar createXMLGregorianCalendar(Date date)
      Creates the XML gregorian calendar.
      Parameters:
      date -
      Returns:
    • createXMLGregorianCalendar

      public static XMLGregorianCalendar createXMLGregorianCalendar(long timeInMillis)
      Creates the XML gregorian calendar.
      Parameters:
      timeInMillis -
      Returns:
    • parseJUDate

      public static Date parseJUDate(String date)
      Parses the JU date.
      Parameters:
      date -
      Returns:
    • parseJUDate

      public static Date parseJUDate(String date, String format)
      Parses the JU date.
      Parameters:
      date -
      format -
      Returns:
    • parseJUDate

      public 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. null is returned if the specified date is null or empty.
      Parameters:
      date -
      format -
      timeZone -
      Returns:
      Throws:
      IllegalArgumentException - if the date given can't be parsed with specified format.
    • parseDate

      public static Date parseDate(String date)
      Parses the date.
      Parameters:
      date -
      Returns:
    • parseDate

      public static Date parseDate(String date, String format)
      Parses the date.
      Parameters:
      date -
      format -
      Returns:
    • parseDate

      public 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. null is returned if the specified date is null or empty.
      Parameters:
      date -
      format -
      timeZone -
      Returns:
    • parseTime

      public static Time parseTime(String date)
      Parses the time.
      Parameters:
      date -
      Returns:
    • parseTime

      public static Time parseTime(String date, String format)
      Parses the time.
      Parameters:
      date -
      format -
      Returns:
    • parseTime

      public static Time parseTime(String date, String format, TimeZone timeZone)
      Converts the specified date with the specified format to a new instance of Time. null is returned if the specified date is null or empty.
      Parameters:
      date -
      format -
      timeZone -
      Returns:
    • parseTimestamp

      public static Timestamp parseTimestamp(String date)
      Parses the timestamp.
      Parameters:
      date -
      Returns:
    • parseTimestamp

      public static Timestamp parseTimestamp(String date, String format)
      Parses the timestamp.
      Parameters:
      date -
      format -
      Returns:
    • parseTimestamp

      public static Timestamp parseTimestamp(String date, String format, TimeZone timeZone)
      Converts the specified date with the specified format to a new instance of Timestamp. null is returned if the specified date is null or empty.
      Parameters:
      date -
      format -
      timeZone -
      Returns:
    • parseCalendar

      @Beta public static Calendar parseCalendar(String calendar)
      Parses the calendar.
      Parameters:
      calendar -
      Returns:
    • parseCalendar

      @Beta public static Calendar parseCalendar(String calendar, String format)
      Parses the calendar.
      Parameters:
      calendar -
      format -
      Returns:
    • parseCalendar

      @Beta public static Calendar parseCalendar(String calendar, String format, TimeZone timeZone)
      Converts the specified calendar with the specified format to a new instance of Calendar. null is returned if the specified date is null or empty.
      Parameters:
      calendar -
      format -
      timeZone -
      Returns:
    • parseGregorianCalendar

      @Beta public static GregorianCalendar parseGregorianCalendar(String calendar)
      Parses the gregorian calendar.
      Parameters:
      calendar -
      Returns:
    • parseGregorianCalendar

      @Beta public static GregorianCalendar parseGregorianCalendar(String calendar, String format)
      Parses the gregorian calendar.
      Parameters:
      calendar -
      format -
      Returns:
    • parseGregorianCalendar

      @Beta public static GregorianCalendar parseGregorianCalendar(String calendar, String format, TimeZone timeZone)
      Converts the specified calendar with the specified format to a new instance of GregorianCalendar. null is returned if the specified date is null or empty.
      Parameters:
      calendar -
      format -
      timeZone -
      Returns:
    • parseXMLGregorianCalendar

      @Beta public static XMLGregorianCalendar parseXMLGregorianCalendar(String calendar)
      Parses the XML gregorian calendar.
      Parameters:
      calendar -
      Returns:
    • parseXMLGregorianCalendar

      @Beta public static XMLGregorianCalendar parseXMLGregorianCalendar(String calendar, String format)
      Parses the XML gregorian calendar.
      Parameters:
      calendar -
      format -
      Returns:
    • parseXMLGregorianCalendar

      @Beta public static XMLGregorianCalendar parseXMLGregorianCalendar(String calendar, String format, TimeZone timeZone)
      Converts the specified calendar with the specified format to a new instance of XMLGregorianCalendar. null is returned if the specified date is null or empty.
      Parameters:
      calendar -
      format -
      timeZone -
      Returns:
    • formatLocalDate

      @Beta public static String formatLocalDate()
      Format current date with format yyyy-MM-dd
      Parameters:
      date -
      Returns:
    • formatLocalDateTime

      @Beta public static String formatLocalDateTime()
      Format current date with format with specified {@code yyyy-MM-dd HH:mm:ss). @param date @return
    • formatCurrentDateTime

      public static String formatCurrentDateTime()
      Format current date with format with specified {@code yyyy-MM-dd'T'HH:mm:ss'Z'). @param date @param format @return
    • formatCurrentTimestamp

      public static String formatCurrentTimestamp()
      Format current date with format with specified {@code yyyy-MM-dd'T'HH:mm:ss.SSS'Z'). @param date @param format @return
    • format

      public static String format(Date date)
      Format specified date with format yyyy-MM-dd'T'HH:mm:ss.SSS'Z' if it's a Timestamp, otherwise format it with format yyyy-MM-dd'T'HH:mm:ss'Z'.
      Parameters:
      date -
      Returns:
    • format

      public static String format(Date date, String format)
      Parameters:
      date -
      format -
      Returns:
    • format

      public static String format(Date date, String format, TimeZone timeZone)
      Parameters:
      date -
      format -
      timeZone -
      Returns:
    • format

      public static void format(Writer writer, Date date)
      Parameters:
      writer -
      date -
    • format

      public static void format(Writer writer, Date date, String format)
      Parameters:
      writer -
      date -
      format -
    • format

      public static void format(Writer writer, Date date, String format, TimeZone timeZone)
      Parameters:
      writer -
      date -
      format -
      timeZone -
    • format

      public static String format(Calendar c)
      Parameters:
      c -
      Returns:
    • format

      public static String format(Calendar c, String format)
      Parameters:
      c -
      format -
      Returns:
    • format

      public static String format(Calendar c, String format, TimeZone timeZone)
      Parameters:
      c -
      format -
      timeZone -
      Returns:
    • format

      public static void format(Writer writer, Calendar c)
      Parameters:
      writer -
      c -
    • format

      public static void format(Writer writer, Calendar c, String format)
      Parameters:
      writer -
      c -
      format -
    • format

      public static void format(Writer writer, Calendar c, String format, TimeZone timeZone)
      Parameters:
      writer -
      c -
      format -
      timeZone -
    • format

      public static String format(XMLGregorianCalendar c)
      Parameters:
      c -
      Returns:
    • format

      public static String format(XMLGregorianCalendar c, String format)
      Parameters:
      c -
      format -
      Returns:
    • format

      public static String format(XMLGregorianCalendar c, String format, TimeZone timeZone)
      Parameters:
      c -
      format -
      timeZone -
      Returns:
    • format

      public static void format(Writer writer, XMLGregorianCalendar c)
      Parameters:
      writer -
      c -
    • format

      public static void format(Writer writer, XMLGregorianCalendar c, String format)
      Parameters:
      writer -
      c -
      format -
    • format

      public static void format(Writer writer, XMLGregorianCalendar c, String format, TimeZone timeZone)
      Parameters:
      writer -
      c -
      format -
      timeZone -
    • setYears

      public static <T extends Date> T setYears(T date, int amount)
      Copied from Apache Commons Lang under Apache License v2.
      Sets the years field to a date returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      date - the date, not null
      amount - the amount to set
      Returns:
      a new Date set with the specified value
      Throws:
      IllegalArgumentException - if the date is null
      Since:
      2.4
    • setMonths

      public static <T extends Date> T setMonths(T date, int amount)
      Copied from Apache Commons Lang under Apache License v2.
      Sets the months field to a date returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      date - the date, not null
      amount - the amount to set
      Returns:
      a new Date set with the specified value
      Throws:
      IllegalArgumentException - if the date is null
      Since:
      2.4
    • setDays

      public static <T extends Date> T setDays(T date, int amount)
      Copied from Apache Commons Lang under Apache License v2.
      Sets the day of month field to a date returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      date - the date, not null
      amount - the amount to set
      Returns:
      a new Date set with the specified value
      Throws:
      IllegalArgumentException - if the date is null
      Since:
      2.4
    • setHours

      public static <T extends Date> T setHours(T date, int amount)
      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 original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      date - the date, not null
      amount - the amount to set
      Returns:
      a new Date set with the specified value
      Throws:
      IllegalArgumentException - if the date is null
      Since:
      2.4
    • setMinutes

      public static <T extends Date> T setMinutes(T date, int amount)
      Copied from Apache Commons Lang under Apache License v2.
      Sets the minute field to a date returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      date - the date, not null
      amount - the amount to set
      Returns:
      a new Date set with the specified value
      Throws:
      IllegalArgumentException - if the date is null
      Since:
      2.4
    • setSeconds

      public static <T extends Date> T setSeconds(T date, int amount)
      Copied from Apache Commons Lang under Apache License v2.
      Sets the seconds field to a date returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      date - the date, not null
      amount - the amount to set
      Returns:
      a new Date set with the specified value
      Throws:
      IllegalArgumentException - if the date is null
      Since:
      2.4
    • setMilliseconds

      public static <T extends Date> T setMilliseconds(T date, int amount)
      Copied from Apache Commons Lang under Apache License v2.
      Sets the milliseconds field to a date returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      date - the date, not null
      amount - 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 public static <T extends Date> T roll(T date, long amount, TimeUnit unit)
      Deprecated.
      replaced by addYears/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 public static <T extends Date> T roll(T date, long amount, CalendarField unit)
      Deprecated.
      replaced by addYears/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 public static <T extends Calendar> T roll(T calendar, long amount, TimeUnit unit)
      Deprecated.
      replaced by addYears/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 public static <T extends Calendar> T roll(T calendar, long amount, CalendarField unit)
      Deprecated.
      replaced by addYears/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

      public static <T extends Date> T addYears(T date, int amount)
      Adds a number of years to a date returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      date - the date, not null
      amount - the amount to add, may be negative
      Returns:
      Throws:
      IllegalArgumentException - if the date is null
    • addMonths

      public static <T extends Date> T addMonths(T date, int amount)
      Adds a number of months to a date returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      date - the date, not null
      amount - the amount to add, may be negative
      Returns:
      Throws:
      IllegalArgumentException - if the date is null
    • addWeeks

      public static <T extends Date> T addWeeks(T date, int amount)
      Adds a number of weeks to a date returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      date - the date, not null
      amount - the amount to add, may be negative
      Returns:
      Throws:
      IllegalArgumentException - if the date is null
    • addDays

      public static <T extends Date> T addDays(T date, int amount)
      Adds a number of days to a date returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      date - the date, not null
      amount - the amount to add, may be negative
      Returns:
      Throws:
      IllegalArgumentException - if the date is null
    • addHours

      public static <T extends Date> T addHours(T date, int amount)
      Adds a number of hours to a date returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      date - the date, not null
      amount - the amount to add, may be negative
      Returns:
      Throws:
      IllegalArgumentException - if the date is null
    • addMinutes

      public static <T extends Date> T addMinutes(T date, int amount)
      Adds a number of minutes to a date returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      date - the date, not null
      amount - the amount to add, may be negative
      Returns:
      Throws:
      IllegalArgumentException - if the date is null
    • addSeconds

      public static <T extends Date> T addSeconds(T date, int amount)
      Adds a number of seconds to a date returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      date - the date, not null
      amount - the amount to add, may be negative
      Returns:
      Throws:
      IllegalArgumentException - if the date is null
    • addMilliseconds

      public static <T extends Date> T addMilliseconds(T date, int amount)
      Adds a number of milliseconds to a date returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      date - the date, not null
      amount - the amount to add, may be negative
      Returns:
      Throws:
      IllegalArgumentException - if the date is null
    • addYears

      public static <T extends Calendar> T addYears(T calendar, int amount)
      Adds a number of years to a calendar returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      calendar - the calendar, not null
      amount - the amount to add, may be negative
      Returns:
      Throws:
      IllegalArgumentException - if the calendar is null
    • addMonths

      public static <T extends Calendar> T addMonths(T calendar, int amount)
      Adds a number of months to a calendar returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      calendar - the calendar, not null
      amount - the amount to add, may be negative
      Returns:
      Throws:
      IllegalArgumentException - if the calendar is null
    • addWeeks

      public static <T extends Calendar> T addWeeks(T calendar, int amount)
      Adds a number of weeks to a calendar returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      calendar - the calendar, not null
      amount - the amount to add, may be negative
      Returns:
      Throws:
      IllegalArgumentException - if the calendar is null
    • addDays

      public static <T extends Calendar> T addDays(T calendar, int amount)
      Adds a number of days to a calendar returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      calendar - the calendar, not null
      amount - the amount to add, may be negative
      Returns:
      Throws:
      IllegalArgumentException - if the calendar is null
    • addHours

      public static <T extends Calendar> T addHours(T calendar, int amount)
      Adds a number of hours to a calendar returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      calendar - the calendar, not null
      amount - the amount to add, may be negative
      Returns:
      Throws:
      IllegalArgumentException - if the calendar is null
    • addMinutes

      public static <T extends Calendar> T addMinutes(T calendar, int amount)
      Adds a number of minutes to a calendar returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      calendar - the calendar, not null
      amount - the amount to add, may be negative
      Returns:
      Throws:
      IllegalArgumentException - if the calendar is null
    • addSeconds

      public static <T extends Calendar> T addSeconds(T calendar, int amount)
      Adds a number of seconds to a calendar returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      calendar - the calendar, not null
      amount - the amount to add, may be negative
      Returns:
      Throws:
      IllegalArgumentException - if the calendar is null
    • addMilliseconds

      public static <T extends Calendar> T addMilliseconds(T calendar, int amount)
      Adds a number of milliseconds to a calendar returning a new object. The original Date is unchanged.
      Type Parameters:
      T -
      Parameters:
      calendar - the calendar, not null
      amount - the amount to add, may be negative
      Returns:
      Throws:
      IllegalArgumentException - if the calendar is null
    • round

      public static <T extends Date> T round(T date, int field)
      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 null
      field - the field from Calendar or SEMI_MONTH
      Returns:
      Throws:
      ArithmeticException - if the year is over 280 million
    • round

      public static <T extends Date> T round(T date, CalendarField field)
      Type Parameters:
      T -
      Parameters:
      date -
      field -
      Returns:
    • round

      public static <T extends Calendar> T round(T calendar, int field)
      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 null
      field - the field from Calendar or SEMI_MONTH
      Returns:
      Throws:
      IllegalArgumentException - if the date is null
      ArithmeticException - if the year is over 280 million
    • round

      public static <T extends Calendar> T round(T calendar, CalendarField field)
      Type Parameters:
      T -
      Parameters:
      calendar -
      field -
      Returns:
    • truncate

      public static <T extends Date> T truncate(T date, int field)
      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 null
      field - the field from Calendar or SEMI_MONTH
      Returns:
      Throws:
      IllegalArgumentException - if the date is null
      ArithmeticException - if the year is over 280 million
    • truncate

      public static <T extends Date> T truncate(T date, CalendarField field)
      Type Parameters:
      T -
      Parameters:
      date -
      field -
      Returns:
    • truncate

      public static <T extends Calendar> T truncate(T calendar, int field)
      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 null
      field - the field from Calendar or SEMI_MONTH
      Returns:
      Throws:
      IllegalArgumentException - if the date is null
      ArithmeticException - if the year is over 280 million
    • truncate

      public static <T extends Calendar> T truncate(T calendar, CalendarField field)
      Type Parameters:
      T -
      Parameters:
      calendar -
      field -
      Returns:
    • ceiling

      public static <T extends Date> T ceiling(T date, int field)
      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 null
      field - the field from Calendar or SEMI_MONTH
      Returns:
      Throws:
      IllegalArgumentException - if the date is null
      ArithmeticException - if the year is over 280 million
      Since:
      2.5
    • ceiling

      public static <T extends Date> T ceiling(T date, CalendarField field)
      Type Parameters:
      T -
      Parameters:
      date -
      field -
      Returns:
    • ceiling

      public static <T extends Calendar> T ceiling(T calendar, int field)
      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 null
      field - the field from Calendar or SEMI_MONTH
      Returns:
      Throws:
      IllegalArgumentException - if the date is null
      ArithmeticException - if the year is over 280 million
      Since:
      2.5
    • ceiling

      public static <T extends Calendar> T ceiling(T calendar, CalendarField field)
      Type Parameters:
      T -
      Parameters:
      calendar -
      field -
      Returns:
    • truncatedEquals

      public static boolean truncatedEquals(Calendar cal1, Calendar cal2, CalendarField field)
      Parameters:
      cal1 -
      cal2 -
      field -
      Returns:
      See Also:
    • truncatedEquals

      public static boolean truncatedEquals(Calendar cal1, Calendar cal2, int field)
      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, not null
      cal2 - the second calendar, not null
      field - the field from Calendar
      Returns:
      true if equal; otherwise false
      Throws:
      IllegalArgumentException - if any argument is null
      Since:
      3.0
      See Also:
    • truncatedEquals

      public static boolean truncatedEquals(Date date1, Date date2, CalendarField field)
      Parameters:
      date1 -
      date2 -
      field -
      Returns:
      See Also:
    • truncatedEquals

      public static boolean truncatedEquals(Date date1, Date date2, int field)
      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, not null
      date2 - the second date, not null
      field - the field from Calendar
      Returns:
      true if equal; otherwise false
      Throws:
      IllegalArgumentException - if any argument is null
      Since:
      3.0
      See Also:
    • truncatedCompareTo

      public static int truncatedCompareTo(Calendar cal1, Calendar cal2, CalendarField field)
      Parameters:
      cal1 -
      cal2 -
      field -
      Returns:
      See Also:
    • truncatedCompareTo

      public static int truncatedCompareTo(Calendar cal1, Calendar cal2, int field)
      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, not null
      cal2 - the second calendar, not null
      field - the field from Calendar
      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 is null
      Since:
      3.0
      See Also:
    • truncatedCompareTo

      public static int truncatedCompareTo(Date date1, Date date2, CalendarField field)
      Parameters:
      date1 -
      date2 -
      field -
      Returns:
      See Also:
    • truncatedCompareTo

      public static int truncatedCompareTo(Date date1, Date date2, int field)
      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, not null
      date2 - the second date, not null
      field - the field from Calendar
      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 is null
      Since:
      3.0
      See Also:
    • getFragmentInMilliseconds

      public static long getFragmentInMilliseconds(Date date, CalendarField fragment)
      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 null
      fragment - the Calendar field part of date to calculate
      Returns:
      number of milliseconds within the fragment of date
      Throws:
      IllegalArgumentException - if the date is null or fragment is not supported
      Since:
      2.4
    • getFragmentInSeconds

      public static long getFragmentInSeconds(Date date, CalendarField fragment)
      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 null
      fragment - the Calendar field part of date to calculate
      Returns:
      number of seconds within the fragment of date
      Throws:
      IllegalArgumentException - if the date is null or fragment is not supported
      Since:
      2.4
    • getFragmentInMinutes

      public static long getFragmentInMinutes(Date date, CalendarField fragment)
      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 null
      fragment - the Calendar field part of date to calculate
      Returns:
      number of minutes within the fragment of date
      Throws:
      IllegalArgumentException - if the date is null or fragment is not supported
      Since:
      2.4
    • getFragmentInHours

      public static long getFragmentInHours(Date date, CalendarField fragment)
      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 null
      fragment - the Calendar field part of date to calculate
      Returns:
      number of hours within the fragment of date
      Throws:
      IllegalArgumentException - if the date is null or fragment is not supported
      Since:
      2.4
    • getFragmentInDays

      public static long getFragmentInDays(Date date, CalendarField fragment)
      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 null
      fragment - the Calendar field part of date to calculate
      Returns:
      number of days within the fragment of date
      Throws:
      IllegalArgumentException - if the date is null or fragment is not supported
      Since:
      2.4
    • getFragmentInMilliseconds

      public static long getFragmentInMilliseconds(Calendar calendar, CalendarField fragment)
      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 null
      fragment - the Calendar field part of calendar to calculate
      Returns:
      number of milliseconds within the fragment of date
      Throws:
      IllegalArgumentException - if the date is null or fragment is not supported
      Since:
      2.4
    • getFragmentInSeconds

      public static long getFragmentInSeconds(Calendar calendar, CalendarField fragment)
      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 null
      fragment - the Calendar field part of calendar to calculate
      Returns:
      number of seconds within the fragment of date
      Throws:
      IllegalArgumentException - if the date is null or fragment is not supported
      Since:
      2.4
    • getFragmentInMinutes

      public static long getFragmentInMinutes(Calendar calendar, CalendarField fragment)
      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 null
      fragment - the Calendar field part of calendar to calculate
      Returns:
      number of minutes within the fragment of date
      Throws:
      IllegalArgumentException - if the date is null or fragment is not supported
      Since:
      2.4
    • getFragmentInHours

      public static long getFragmentInHours(Calendar calendar, CalendarField fragment)
      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 null
      fragment - the Calendar field part of calendar to calculate
      Returns:
      number of hours within the fragment of date
      Throws:
      IllegalArgumentException - if the date is null or fragment is not supported
      Since:
      2.4
    • getFragmentInDays

      public static long getFragmentInDays(Calendar calendar, CalendarField fragment)
      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 null
      fragment - the Calendar field part of calendar to calculate
      Returns:
      number of days within the fragment of date
      Throws:
      IllegalArgumentException - if the date is null or fragment is not supported
      Since:
      2.4
    • isSameDay

      public static boolean isSameDay(Date date1, Date date2)
      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 null
      date2 - the second date, not altered, not null
      Returns:
      true if they represent the same day
      Throws:
      IllegalArgumentException - if either date is null
      Since:
      2.1
    • isSameDay

      public static boolean isSameDay(Calendar cal1, Calendar cal2)
      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 null
      cal2 - the second calendar, not altered, not null
      Returns:
      true if they represent the same day
      Throws:
      IllegalArgumentException - if either calendar is null
      Since:
      2.1
    • isSameMonth

      public static boolean isSameMonth(Date date1, Date date2)
    • isSameMonth

      public static boolean isSameMonth(Calendar cal1, Calendar cal2)
    • isSameYear

      public static boolean isSameYear(Date date1, Date date2)
    • isSameYear

      public static boolean isSameYear(Calendar cal1, Calendar cal2)
    • isSameInstant

      public static boolean isSameInstant(Date date1, Date date2)
      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 null
      date2 - the second date, not altered, not null
      Returns:
      true if they represent the same millisecond instant
      Throws:
      IllegalArgumentException - if either date is null
      Since:
      2.1
    • isSameInstant

      public static boolean isSameInstant(Calendar cal1, Calendar cal2)
      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 null
      cal2 - the second calendar, not altered, not null
      Returns:
      true if they represent the same millisecond instant
      Throws:
      IllegalArgumentException - if either date is null
      Since:
      2.1
    • isSameLocalTime

      public static boolean isSameLocalTime(Calendar cal1, Calendar cal2)
      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 null
      cal2 - the second calendar, not altered, not null
      Returns:
      true if they represent the same millisecond instant
      Throws:
      IllegalArgumentException - if either date is null
      Since:
      2.1
    • isLastDateOfMonth

      public static boolean isLastDateOfMonth(Date date)
    • isLastDateOfYear

      public static boolean isLastDateOfYear(Date date)
    • getLastDateOfMonth

      public static int getLastDateOfMonth(Date date)
    • getLastDateOfYear

      public static int getLastDateOfYear(Date date)