public class DateUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
containsParsableDates(Iterable<?> iterable)
Checks if all the elements are parsable dates.
|
static boolean |
containsParsableDatesIso8601(Iterable<?> iterable)
Checks if all the elements are parsable dates.
|
static boolean |
containsParsableDatesRfc3339(Iterable<?> iterable)
Checks if all the elements are parsable dates.
|
static long |
daysBetween(Date firstDate,
Date secondDate)
Calculates the number of days between two dates
|
static Date |
endOfMonth(Date date)
Returns the date corresponding to the last day of the month given a source date
|
static String |
formatDate(Date date,
String pattern)
Converts the given date into string with the the given
pattern |
static int |
getDateField(Date date,
int calendarCode)
Returns the field referenced by the given
calendarCode in the specified date. |
static int |
getIsoWeekNumber(Date date)
Returns the ISO week number in the year given a date.
|
static int |
getMonth(Date date)
Returns the month number (January = 1) for the given date.
|
static int |
getQuarter(Date date)
Returns the quarter of the year.
|
static boolean |
isLeapYear(Date date)
Returns true if the given date is a leap year, that is, an year with 366 days, the
extra day designated as February 29.
|
static boolean |
isLeapYear(int year)
Returns true if the given year is a leap year, that is, an year with 366 days, the
extra day designated as February 29.
|
static boolean |
isParsable(Object object)
Checks whether the given object can be a valid date.
|
static boolean |
isParsableIso8601(String string)
Checks whether the given string can be a valid date based on a set of common ISO-8601
format variations.
|
static boolean |
isParsableRfc3339(String string)
Checks whether the given string can be a valid date in RFC-3339 format.
|
static Date |
parseDate(Object object)
Converts the given object into
Date. |
static Date |
parseDate(String string,
String... patterns)
Converts the given string into
Date by applying the specified
patterns until the operation succeeds |
static Date |
parseDateIso8601(String string)
Converts the given string into
Date by trying a set of common
ISO-8601 parse patterns. |
static Date |
parseDateRfc3339(String string)
Converts the given string into
Date based in RFC-3339 format. |
static Calendar |
toCalendar(Date date)
Converts a date to Calendar
|
public static String formatDate(Date date, String pattern)
patterndate - the date to be formattedpattern - the date format pattern to be usedDatepublic static Date parseDate(String string, String... patterns) throws ParseException
Date by applying the specified
patterns until the operation succeedsstring - the string to be convertedpatterns - the date format patterns to be usedIllegalArgumentException - if a null string or pattern is receivedParseException - if the date can not be parsedpublic static Date parseDateRfc3339(String string)
Date based in RFC-3339 format.string - the string to be convertedIllegalArgumentException - if the date can not be parsedpublic static Date parseDateIso8601(String string)
Date by trying a set of common
ISO-8601 parse patterns.string - the string to be convertedIllegalArgumentException - if the date cannot be parsedpublic static Date parseDate(Object object)
Date. It supports objects of type
Instant, and valid strings in RFC-3339 format and other common
ISO-8601 format variations.object - the object to be convertedIllegalArgumentException - if the date can not be p'varsedpublic static boolean isParsable(Object object)
object - the object to be evaluatedpublic static boolean isParsableRfc3339(String string)
string - the object to be evaluatedpublic static boolean isParsableIso8601(String string)
string - the string to be evaluatedpublic static boolean containsParsableDates(Iterable<?> iterable)
Date, Instant or Strings in RFC-3339 or a set of
commonly-used ISO-8601 format variations.iterable - the iterable to be evaluatedpublic static boolean containsParsableDatesRfc3339(Iterable<?> iterable)
iterable - the iterable whose elements will be evaluatedpublic static boolean containsParsableDatesIso8601(Iterable<?> iterable)
iterable - the iterable whose elements will be evaluatedpublic static Calendar toCalendar(Date date)
date - the Date to be convertedpublic static long daysBetween(Date firstDate, Date secondDate)
firstDate - the first date for the comparisonsecondDate - the seconds date for the comparisonfirstDate and secondDateIllegalArgumentException - if a null date is receivedpublic static boolean isLeapYear(Date date)
date - the date whose year is to be evaluatedtrue if the given year is leap year, false if not.IllegalArgumentException - if a null date is receivedpublic static boolean isLeapYear(int year)
year - the year to be evaluatedtrue if the given year is leap year, false if not.public static int getIsoWeekNumber(Date date)
According to the standard, the first week of the year will be the first one with a minimum of 4 days, starting with Monday.
date - the date to be acceptedpublic static int getMonth(Date date)
date - the date whose month number is to be retrievedpublic static int getQuarter(Date date)
date - the date whose quarter is to be retrievedpublic static int getDateField(Date date, int calendarCode)
calendarCode in the specified date.date - the date whose field is to be retrievedcalendarCode - one of the integer constants from CalendarcalendarCode in the specified dateCopyright © 2021. All rights reserved.