Class DateUtil

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

public abstract class DateUtil extends Object
Since:
1.2.6
Author:
Haiyang Li
  • Field Details

    • UTC_TIME_ZONE

      public static final TimeZone UTC_TIME_ZONE
    • LOCAL_TIME_ZONE

      public static final TimeZone LOCAL_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

    • 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:
    • 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

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

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

      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

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

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

      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

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

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

      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:
    • format

      public static String format(Date date)
      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, CalendarUnit 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, CalendarUnit 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 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
    • 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 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
    • 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 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
    • 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, 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, 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, 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:
    • 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