Package com.jidesoft.utils
Class DateUtils
- java.lang.Object
-
- com.jidesoft.utils.DateUtils
-
public class DateUtils extends java.lang.ObjectDateUtilscontains many useful methods related to Date and Calendar.
-
-
Constructor Summary
Constructors Constructor Description DateUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.util.CalendaradjustDate(java.util.Calendar calendar, int differenceInDay)Adjusts the Calendar to several days before or after the current date.static booleanisAtMonth(java.util.Calendar cal, int month)Checks if the calendar object is in the specified month, regardless of the year.static booleanisAtQuarter(java.util.Calendar cal, int quarter)Checks if the calendar object is in the specified quarter, regardless of the year.static booleanisLastMonth(java.util.Calendar cal)Checks if the calendar object is last month.static booleanisLastQuarter(java.util.Calendar cal)Checks if the calendar object is last quarter.static booleanisLastWeek(java.util.Calendar cal)Checks if the calendar object is last week.static booleanisLastYear(java.util.Calendar cal)Checks if the calendar object is last year.static booleanisNextMonth(java.util.Calendar cal)Checks if the calendar object is next month.static booleanisNextQuarter(java.util.Calendar cal)Checks if the calendar object is next quarter.static booleanisNextWeek(java.util.Calendar cal)Checks if the calendar object is next week.static booleanisNextYear(java.util.Calendar cal)Checks if the calendar object is next year.static booleanisThisMonth(java.util.Calendar cal)Checks if the calendar object is same month as today.static booleanisThisQuarter(java.util.Calendar cal)Checks if the calendar object is same quarter as today.static booleanisThisWeek(java.util.Calendar cal)Checks if the calendar object is same week as today.static booleanisThisYear(java.util.Calendar cal)Checks if the calendar object is same year as today.static booleanisToday(java.util.Calendar cal)Checks if the calendar object is same date as today.static booleanisTomorrow(java.util.Calendar cal)Checks if the calendar object is same date as tomorrow.static booleanisYesterday(java.util.Calendar cal)Checks if the calendar object is same date as yesterday.static java.util.Datemax(java.util.List<java.util.Date> dates)Deprecated.replaced bymaxDates(java.util.List)to comply with the new compilation regulation.static java.util.CalendarmaxCalendars(java.util.List<java.util.Calendar> calendars)Returns the maximum Calendar in the Calendar list.static java.util.DatemaxDates(java.util.List<java.util.Date> dates)Returns the maximum Date in the Date list.static java.util.Datemin(java.util.List<java.util.Date> dates)Deprecated.replaced byminDates(java.util.List)to comply with the new compilation regulation.static java.util.CalendarminCalendars(java.util.List<java.util.Calendar> calendars)Returns the minimum Calendar in the Calendar list.static java.util.DateminDates(java.util.List<java.util.Date> dates)Returns the minimum Date in the Date list.static TimeRangerangeCalendars(java.util.List<java.util.Calendar> calendars)Returns the range of Calendars in the Calendar list.static TimeRangerangeDates(java.util.List<java.util.Date> dates)Returns the range of date in the Calendar list.
-
-
-
Method Detail
-
isToday
public static boolean isToday(java.util.Calendar cal)
Checks if the calendar object is same date as today.- Parameters:
cal- the calendar object- Returns:
- true if the calendar object is the same date as today.
-
isThisWeek
public static boolean isThisWeek(java.util.Calendar cal)
Checks if the calendar object is same week as today.- Parameters:
cal- the calendar object- Returns:
- true if the calendar object is the same week as today.
-
isThisMonth
public static boolean isThisMonth(java.util.Calendar cal)
Checks if the calendar object is same month as today.- Parameters:
cal- the calendar object- Returns:
- true if the calendar object is the same month as today.
-
isThisQuarter
public static boolean isThisQuarter(java.util.Calendar cal)
Checks if the calendar object is same quarter as today.- Parameters:
cal- the calendar object- Returns:
- true if the calendar object is the same quarter as today.
-
isThisYear
public static boolean isThisYear(java.util.Calendar cal)
Checks if the calendar object is same year as today.- Parameters:
cal- the calendar object- Returns:
- true if the calendar object is the same year as today.
-
isYesterday
public static boolean isYesterday(java.util.Calendar cal)
Checks if the calendar object is same date as yesterday.- Parameters:
cal- the calendar object- Returns:
- true if the calendar object is the same date as yesterday.
-
isLastWeek
public static boolean isLastWeek(java.util.Calendar cal)
Checks if the calendar object is last week.- Parameters:
cal- the calendar object- Returns:
- true if the calendar object is last week.
-
isLastMonth
public static boolean isLastMonth(java.util.Calendar cal)
Checks if the calendar object is last month.- Parameters:
cal- the calendar object- Returns:
- true if the calendar object is last month.
-
isLastQuarter
public static boolean isLastQuarter(java.util.Calendar cal)
Checks if the calendar object is last quarter.- Parameters:
cal- the calendar object- Returns:
- true if the calendar object is last quarter.
-
isLastYear
public static boolean isLastYear(java.util.Calendar cal)
Checks if the calendar object is last year.- Parameters:
cal- the calendar object- Returns:
- true if the calendar object is last year.
-
isTomorrow
public static boolean isTomorrow(java.util.Calendar cal)
Checks if the calendar object is same date as tomorrow.- Parameters:
cal- the calendar object- Returns:
- true if the calendar object is the same date as tomorrow.
-
isNextWeek
public static boolean isNextWeek(java.util.Calendar cal)
Checks if the calendar object is next week.- Parameters:
cal- the calendar object- Returns:
- true if the calendar object is next week.
-
isNextMonth
public static boolean isNextMonth(java.util.Calendar cal)
Checks if the calendar object is next month.- Parameters:
cal- the calendar object- Returns:
- true if the calendar object is next month.
-
isNextQuarter
public static boolean isNextQuarter(java.util.Calendar cal)
Checks if the calendar object is next quarter.- Parameters:
cal- the calendar object- Returns:
- true if the calendar object is next quarter.
-
isNextYear
public static boolean isNextYear(java.util.Calendar cal)
Checks if the calendar object is next year.- Parameters:
cal- the calendar object- Returns:
- true if the calendar object is next year.
-
isAtMonth
public static boolean isAtMonth(java.util.Calendar cal, int month)Checks if the calendar object is in the specified month, regardless of the year.- Parameters:
cal- the calendar object.month- the month, starting from 0 for January. You can use the value defined in Calendar such as Calendar.JANUARY, Calendar.FEBRUARY, etc.- Returns:
- true if the calendar object is the specified month.
-
isAtQuarter
public static boolean isAtQuarter(java.util.Calendar cal, int quarter)Checks if the calendar object is in the specified quarter, regardless of the year.- Parameters:
cal- the calendar object.quarter- the quarter, starting from 1 for the first quarter (including January, February, and March).- Returns:
- true if the calendar object is the specified quarter.
-
adjustDate
public static java.util.Calendar adjustDate(java.util.Calendar calendar, int differenceInDay)Adjusts the Calendar to several days before or after the current date.- Parameters:
calendar- the Calendar object to be adjusted.differenceInDay- the difference in days. It accepts both position and negative number.- Returns:
- the calendar after the adjustment. It should always be the same instance as the calendar parameter.
-
min
@Deprecated public static java.util.Date min(java.util.List<java.util.Date> dates)
Deprecated.replaced byminDates(java.util.List)to comply with the new compilation regulation. We have to delete the min(List) in releases earlier than 2.9.4 due to the same reason. Returns the minimum Date in the Date list.- Parameters:
dates- the list of Date to calculate the minimum.- Returns:
- the minimum date in the Date list.
-
max
@Deprecated public static java.util.Date max(java.util.List<java.util.Date> dates)
Deprecated.replaced bymaxDates(java.util.List)to comply with the new compilation regulation. We have to delete the max(List) in releases earlier than 2.9.4 due to the same reason. Returns the maximum Date in the Date list.- Parameters:
dates- the list of Date to calculate the maximum.- Returns:
- the maximum date in the Date list.
-
minDates
public static java.util.Date minDates(java.util.List<java.util.Date> dates)
Returns the minimum Date in the Date list.- Parameters:
dates- the list of Date to calculate the minimum.- Returns:
- the minimum date in the Date list.
-
maxDates
public static java.util.Date maxDates(java.util.List<java.util.Date> dates)
Returns the maximum Date in the Date list.- Parameters:
dates- the list of Date to calculate the maximum.- Returns:
- the maximum date in the Date list.
-
rangeDates
public static TimeRange rangeDates(java.util.List<java.util.Date> dates)
Returns the range of date in the Calendar list.- Parameters:
dates- the list of Dates to calculate the maximum.- Returns:
- the range date in the Calendar list.
-
minCalendars
public static java.util.Calendar minCalendars(java.util.List<java.util.Calendar> calendars)
Returns the minimum Calendar in the Calendar list.- Parameters:
calendars- the list of Calendar to calculate the minimum.- Returns:
- the minimum calendar in the Calendar list.
-
maxCalendars
public static java.util.Calendar maxCalendars(java.util.List<java.util.Calendar> calendars)
Returns the maximum Calendar in the Calendar list.- Parameters:
calendars- the list of Calendar to calculate the maximum.- Returns:
- the maximum calendar in the Calendar list.
-
rangeCalendars
public static TimeRange rangeCalendars(java.util.List<java.util.Calendar> calendars)
Returns the range of Calendars in the Calendar list.- Parameters:
calendars- the list of Calendar to calculate the maximum.- Returns:
- the range of calendars in the Calendar list.
-
-