java.util.Calendar and java.util.Date object.
DateUtils contains a lot of common methods considering manipulations of Dates or Calendars. Some methods require some extra explanation. The truncate, ceiling and round methods could be considered the Math.floor(), Math.ceil() or Math.round versions for dates This way date-fields will be ignored in bottom-up order. As a complement to these methods we've introduced some fragment-methods. With these methods the Date-fields will be ignored in top-down order. Since a date without a year is not a valid date, you have to decide in what kind of date-field you want your result, for instance milliseconds or days.
Several methods are provided for adding to Date objects, of the form
addXXX(Date date, int amount). It is important to note these methods
use a Calendar internally (with default time zone and locale) and may
be affected by changes to daylight saving time (DST).
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | DateUtils.
Date iterator. |
| private static enum | DateUtils.
Calendar modification types. |
| Modifier and Type | Field and Description |
|---|---|
| private static final int[][] | |
| public static final long | MILLIS_PER_DAY
Number of milliseconds in a standard day. |
| public static final long | MILLIS_PER_HOUR
Number of milliseconds in a standard hour. |
| public static final long | MILLIS_PER_MINUTE
Number of milliseconds in a standard minute. |
| public static final long | MILLIS_PER_SECOND
Number of milliseconds in a standard second. |
| public static final int | RANGE_MONTH_MONDAY
A month range, the week starting on Monday. |
| public static final int | RANGE_MONTH_SUNDAY
A month range, the week starting on Sunday. |
| public static final int | RANGE_WEEK_CENTER
A week range, centered around the day focused. |
| public static final int | RANGE_WEEK_MONDAY
A week range, starting on Monday. |
| public static final int | RANGE_WEEK_RELATIVE
A week range, starting on the day focused. |
| public static final int | RANGE_WEEK_SUNDAY
A week range, starting on Sunday. |
| 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. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private static Date | |
| public static Date | |
| public static Date | |
| public static Date | Returns: the newDate with the amount added.the date, not null. date, final int the amount to add, may be negative. amount)Adds a number of milliseconds to a date returning a new object. |
| public static Date | Returns: the newDate with the amount added.the date, not null. date, final int the amount to add, may be negative. amount)Adds a number of minutes to a date returning a new object. |
| public static Date | |
| public static Date | Returns: the newDate with the amount added.the date, not null. date, final int the amount to add, may be negative. amount)Adds a number of seconds to a date returning a new object. |
| public static Date | |
| public static Date | |
| public static Calendar | |
| public static Date | |
| public static Date | |
| private static long | Returns: number of units within the fragment of the calendar.the calendar to work with, not null. calendar, final int the Calendar field part of calendar to calculate. fragment, final TimeUnit the time unit. unit)Gets a Calendar fragment for any unit. |
| private static long | Returns: number of units within the fragment of the date.the date to work with, not null. date, final int the Calendar field part of date to calculate. fragment, final TimeUnit the time unit. unit)Gets a Date fragment for any unit. |
| public static long | Returns: number of days within the fragment of date.the calendar to work with, not null. calendar, final int the fragment)Calendar field part of calendar to calculate.Gets the number of days within the fragment. |
| public static long | Returns: number of days within the fragment of date.the date to work with, not null. date, final int the fragment)Calendar field part of date to calculate.Gets the number of days within the fragment. |
| public static long | Returns: number of hours within the fragment of date.the calendar to work with, not null. calendar, final int the fragment)Calendar field part of calendar to calculate.Gets the number of hours within the fragment. |
| public static long | Returns: number of hours within the fragment of date.the date to work with, not null. date, final int the fragment)Calendar field part of date to calculate.Gets the number of hours within the fragment. |
| public static long | Returns: number of milliseconds within the fragment of date.the calendar to work with, not null. calendar, final int the fragment)Calendar field part of calendar to calculate.Gets the number of milliseconds within the fragment. |
| public static long | Returns: number of milliseconds within the fragment of date.the date to work with, not null. date, final int the fragment)Calendar field part of date to calculate.Gets the number of milliseconds within the fragment. |
| public static long | Returns: number of minutes within the fragment of date.the calendar to work with, not null. calendar, final int the fragment)Calendar field part of calendar to calculate.Gets the number of minutes within the fragment. |
| public static long | Returns: number of minutes within the fragment of date.the date to work with, not null. date, final int the fragment)Calendar field part of date to calculate.Gets the number of minutes within the fragment. |
| public static long | Returns: number of seconds within the fragment of date.the calendar to work with, not null. calendar, final int the fragment)Calendar field part of calendar to calculate.Gets the number of seconds within the fragment. |
| public static long | Returns: number of seconds within the fragment of date.the date to work with, not null. date, final int the fragment)Calendar field part of date to calculate.Gets the number of seconds within the fragment. |
| public static boolean | |
| public static boolean | |
| public static boolean | Returns: true if they represent the same millisecond instant.the first calendar, not altered, not null. cal1, final Calendar the second calendar, not altered, not null. cal2)Tests whether two calendar objects represent the same instant in time. |
| public static boolean | Returns: true if they represent the same millisecond instant.the first date, not altered, not null. date1, final Date the second date, not altered, not null. date2)Tests whether two date objects represent the same instant in time. |
| public static boolean | Returns: true if they represent the same millisecond instant.the first calendar, not altered, not null. cal1, final Calendar the second calendar, not altered, not null. cal2)Tests whether two calendar objects represent the same local time. |
| public static Iterator | Returns: the date iterator, not null.the date to work with, not null. calendar, final int the style constant to use. Must be one of
rangeStyle)DateUtils#RANGE_MONTH_SUNDAY,
DateUtils#RANGE_MONTH_MONDAY,
DateUtils#RANGE_WEEK_SUNDAY,
DateUtils#RANGE_WEEK_MONDAY,
DateUtils#RANGE_WEEK_RELATIVE,
DateUtils#RANGE_WEEK_CENTER.Constructs an |
| public static Iterator | Returns: the date iterator, not null, not null.the date to work with, not null. focus, final int the style constant to use. Must be one of
rangeStyle)DateUtils#RANGE_MONTH_SUNDAY,
DateUtils#RANGE_MONTH_MONDAY,
DateUtils#RANGE_WEEK_SUNDAY,
DateUtils#RANGE_WEEK_MONDAY,
DateUtils#RANGE_WEEK_RELATIVE,
DateUtils#RANGE_WEEK_CENTER.Constructs an |
| public static Iterator | Returns: the date iterator, not null.the style constant to use. Must be one of the range
styles listed for the rangeStyle)iterator(Calendar, int) method.Constructs an |
| private static Calendar | Returns: the given calendar.the calendar, not null. val, final int the field constant. field, final DateUtils.type to truncate, round or ceiling. modTypeInternal calculation method. |
| public static Date | Returns: the parsed date.the date to parse, not null. str, final Locale the locale whose date format symbols should be used. If locale, final String... null,
the system locale is used (as per parseDate(String, String.).the date format patterns to use, see SimpleDateFormat, not null. parsePatterns)Parses a string representing a date by trying a variety of different parsers, using the default date format symbols for the given locale. |
| public static Date | |
| public static Date | Returns: the parsed date.the date to parse, not null. str, final Locale the locale whose date format symbols should be used. If locale, final String... null,
the system locale is used (as per parseDateStrictly(String, String.).the date format patterns to use, see SimpleDateFormat, not null. parsePatterns)Parses a string representing a date by trying a variety of different parsers, using the default date format symbols for the given locale. |
| public static Date | Returns: the parsed date.the date to parse, not null. str, final String... the date format patterns to use, see SimpleDateFormat, not null. parsePatterns)Parses a string representing a date by trying a variety of different parsers. |
| private static Date | Returns: the parsed date.the date to parse, not null. dateStr, final Locale the locale to use when interpreting the pattern, can be null in which
case the default system locale is used. locale, final String[] the date format patterns to use, see SimpleDateFormat, not null. parsePatterns, final boolean Specify whether or not date/time parsing is to be lenient. lenient)Parses a string representing a date by trying a variety of different parsers. |
| public static Calendar | |
| public static Date | |
| public static Date | |
| private static Date | |
| public static Date | |
| public static Date | |
| public static Date | Returns: a newDate set with the specified value.the date, not null. date, final int the amount to set. amount)Sets the milliseconds field to a date returning a new object. |
| public static Date | Returns: a newDate set with the specified value.the date, not null. date, final int the amount to set. amount)Sets the minute field to a date returning a new object. |
| public static Date | |
| public static Date | Returns: a newDate set with the specified value.the date, not null. date, final int the amount to set. amount)Sets the seconds field to a date returning a new object. |
| public static Date | |
| public static Calendar | Returns: the created Calendar.the date to convert to a Calendar. date) |
| public static Calendar | |
| public static LocalDateTime | Returns: a new LocalDateTime.the Date to convert, not null. date)Converts a |
| public static LocalDateTime | Returns: a new LocalDateTime.the Date to convert to a LocalDateTime, not null. date, final TimeZone the time zone, null maps to to the default time zone. timeZone)Converts a |
| public static OffsetDateTime | Returns: a new OffsetDateTime.the Date to convert, not null. date)Converts a |
| public static OffsetDateTime | Returns: a new OffsetDateTime.the Date to convert to a OffsetDateTime, not null. date, final TimeZone the time zone, null maps to to the default time zone. timeZone)Converts a |
| public static ZonedDateTime | Returns: a new ZonedDateTime.the Date to convert, not null. date)Converts a |
| public static ZonedDateTime | Returns: a new ZonedDateTime.the Date to convert to a ZonedDateTime, not null. date, final TimeZone the time zone, null maps to to the default time zone. timeZone)Converts a |
| private static ZoneId | |
| public static Calendar | |
| public static Date | |
| public static Date | |
| public static int | Returns: a negative integer, zero, or a positive integer as the first calendar is less than, equal to, or greater than the second.the first calendar, not cal1, final Calendar null.the second calendar, not cal2, final int null.the field from field)Calendar.Determines how two calendars compare up to no more than the specified most significant field. |
| public static int | Returns: a negative integer, zero, or a positive integer as the first date is less than, equal to, or greater than the second.the first date, not date1, final Date null.the second date, not date2, final int null.the field from field)Calendar.Determines how two dates compare up to no more than the specified most significant field. |
| public static boolean | Returns: true if equal; otherwise false.the first calendar, not cal1, final Calendar null.the second calendar, not cal2, final int null.the field from field)Calendar.Determines if two calendars are equal up to no more than the specified most significant field. |
| public static boolean | Returns: true if equal; otherwise false.the first date, not date1, final Date null.the second date, not date2, final int null.the field from field)Calendar.Determines if two dates are equal up to no more than the specified most significant field. |
| private static void |