Package org.jdesktop.swingx.calendar
Class DateUtils
java.lang.Object
org.jdesktop.swingx.calendar.DateUtils
Utility methods for Date manipulation.
This utility class is replaced by CalendarUtils because day related manipulation are meaningfull relative to a Calendar only. Always doing so against the default calendar instance isn't enough. PENDING JW: move the missing ops. Volunteers, please! Once done, this will be deprecated.
- Author:
- Scott Violet
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longaddDays(long time, int amount) Addsamountdays totimeand returns the resulting time.static DateReturns the last millisecond of the specified date.static longendOfDayInMillis(long date) Returns the last millisecond of the specified date.static intgetDayOfWeek(long date) Returns the day of the week.static intgetDaysDiff(long t1, long t2) Returns the number of days difference betweent1andt2.static intgetDaysDiff(long t1, long t2, boolean checkOverflow) Returns the number of days difference betweent1andt2.static longgetEndOfMonth(long date) Returns the date corresponding to the end of the month.static longgetNextDay(long date, int startOfWeek) Returns the first day afterdatethat has the day of week matchingstartOfWeek.static longgetNextMonth(long date) Returns the next month.static longgetPreviousDay(long date, int startOfWeek) Returns the first day beforedatethat has the day of week matchingstartOfWeek.static longgetPreviousMonth(long date) Returns the previous month.static longgetStartOfMonth(long date) Returns the date corresponding to the start of the month.static booleanisFirstOfMonth(long date) Check, whether the date passed in is the first day of the month.static booleanisFirstOfYear(long date) Check, whether the date passed in is the first day of the year.static longnextDay(long date) Returns the day afterdate.static DateReturns the day afterdate.static longnextWeek(long date) Returns the week afterdate.static longpreviousDay(long date) Returns the day beforedate.static longpreviousWeek(long date) Returns the week beforedate.static DatestartOfDay(Date date) Returns a new Date with the hours, milliseconds, seconds and minutes set to 0.static longstartOfDayInMillis(long date) Returns day in millis with the hours, milliseconds, seconds and minutes set to 0.
-
Constructor Details
-
DateUtils
public DateUtils()
-
-
Method Details
-
endOfDay
Returns the last millisecond of the specified date.- Parameters:
date- Date to calculate end of day from- Returns:
- Last millisecond of
date
-
startOfDay
Returns a new Date with the hours, milliseconds, seconds and minutes set to 0.- Parameters:
date- Date used in calculating start of day- Returns:
- Start of
date
-
startOfDayInMillis
public static long startOfDayInMillis(long date) Returns day in millis with the hours, milliseconds, seconds and minutes set to 0.- Parameters:
date- long used in calculating start of day- Returns:
- Start of
date
-
endOfDayInMillis
public static long endOfDayInMillis(long date) Returns the last millisecond of the specified date.- Parameters:
date- long to calculate end of day from- Returns:
- Last millisecond of
date
-
nextDay
Returns the day afterdate.- Parameters:
date- Date used in calculating next day- Returns:
- Day after
date.
-
addDays
public static long addDays(long time, int amount) Addsamountdays totimeand returns the resulting time.- Parameters:
time- Base timeamount- Amount of increment.- Returns:
- the time + amount days
-
nextDay
public static long nextDay(long date) Returns the day afterdate.- Parameters:
date- Date used in calculating next day- Returns:
- Day after
date.
-
nextWeek
public static long nextWeek(long date) Returns the week afterdate.- Parameters:
date- Date used in calculating next week- Returns:
- week after
date.
-
getDaysDiff
public static int getDaysDiff(long t1, long t2, boolean checkOverflow) Returns the number of days difference betweent1andt2.- Parameters:
t1- Time 1t2- Time 2checkOverflow- indicates whether to check for overflow- Returns:
- Number of days between
startandend
-
getDaysDiff
public static int getDaysDiff(long t1, long t2) Returns the number of days difference betweent1andt2.- Parameters:
t1- Time 1t2- Time 2- Returns:
- Number of days between
startandend
-
isFirstOfYear
public static boolean isFirstOfYear(long date) Check, whether the date passed in is the first day of the year.- Parameters:
date- date to check in millis- Returns:
trueif date corresponds to the first day of a year- See Also:
-
isFirstOfMonth
public static boolean isFirstOfMonth(long date) Check, whether the date passed in is the first day of the month.- Parameters:
date- date to check in millis- Returns:
trueif date corresponds to the first day of a month- See Also:
-
previousDay
public static long previousDay(long date) Returns the day beforedate.- Parameters:
date- Date used in calculating previous day- Returns:
- Day before
date.
-
previousWeek
public static long previousWeek(long date) Returns the week beforedate.- Parameters:
date- Date used in calculating previous week- Returns:
- week before
date.
-
getPreviousDay
public static long getPreviousDay(long date, int startOfWeek) Returns the first day beforedatethat has the day of week matchingstartOfWeek. For example, if you want to find the previous monday relative todateyou would callgetPreviousDay(date, Calendar.MONDAY).- Parameters:
date- Base datestartOfWeek- Calendar constant correspoding to start of week.- Returns:
- start of week, return value will have 0 hours, 0 minutes, 0 seconds and 0 ms.
-
getNextDay
public static long getNextDay(long date, int startOfWeek) Returns the first day afterdatethat has the day of week matchingstartOfWeek. For example, if you want to find the next monday relative todateyou would callgetPreviousDay(date, Calendar.MONDAY).- Parameters:
date- Base datestartOfWeek- Calendar constant correspoding to start of week.- Returns:
- start of week, return value will have 0 hours, 0 minutes, 0 seconds and 0 ms.
-
getPreviousMonth
public static long getPreviousMonth(long date) Returns the previous month.- Parameters:
date- Base date- Returns:
- previous month
-
getNextMonth
public static long getNextMonth(long date) Returns the next month.- Parameters:
date- Base date- Returns:
- next month
-
getStartOfMonth
public static long getStartOfMonth(long date) Returns the date corresponding to the start of the month.- Parameters:
date- Base date- Returns:
- Start of month.
-
getEndOfMonth
public static long getEndOfMonth(long date) Returns the date corresponding to the end of the month.- Parameters:
date- Base date- Returns:
- End of month.
-
getDayOfWeek
public static int getDayOfWeek(long date) Returns the day of the week.- Parameters:
date- date- Returns:
- day of week.
-