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 long
addDays
(long time, int amount) Addsamount
days totime
and returns the resulting time.static Date
Returns the last millisecond of the specified date.static long
endOfDayInMillis
(long date) Returns the last millisecond of the specified date.static int
getDayOfWeek
(long date) Returns the day of the week.static int
getDaysDiff
(long t1, long t2) Returns the number of days difference betweent1
andt2
.static int
getDaysDiff
(long t1, long t2, boolean checkOverflow) Returns the number of days difference betweent1
andt2
.static long
getEndOfMonth
(long date) Returns the date corresponding to the end of the month.static long
getNextDay
(long date, int startOfWeek) Returns the first day afterdate
that has the day of week matchingstartOfWeek
.static long
getNextMonth
(long date) Returns the next month.static long
getPreviousDay
(long date, int startOfWeek) Returns the first day beforedate
that has the day of week matchingstartOfWeek
.static long
getPreviousMonth
(long date) Returns the previous month.static long
getStartOfMonth
(long date) Returns the date corresponding to the start of the month.static boolean
isFirstOfMonth
(long date) Check, whether the date passed in is the first day of the month.static boolean
isFirstOfYear
(long date) Check, whether the date passed in is the first day of the year.static long
nextDay
(long date) Returns the day afterdate
.static Date
Returns the day afterdate
.static long
nextWeek
(long date) Returns the week afterdate
.static long
previousDay
(long date) Returns the day beforedate
.static long
previousWeek
(long date) Returns the week beforedate
.static Date
startOfDay
(Date date) Returns a new Date with the hours, milliseconds, seconds and minutes set to 0.static long
startOfDayInMillis
(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) Addsamount
days totime
and 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 betweent1
andt2
.- Parameters:
t1
- Time 1t2
- Time 2checkOverflow
- indicates whether to check for overflow- Returns:
- Number of days between
start
andend
-
getDaysDiff
public static int getDaysDiff(long t1, long t2) Returns the number of days difference betweent1
andt2
.- Parameters:
t1
- Time 1t2
- Time 2- Returns:
- Number of days between
start
andend
-
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:
true
if 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:
true
if 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 beforedate
that has the day of week matchingstartOfWeek
. For example, if you want to find the previous monday relative todate
you 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 afterdate
that has the day of week matchingstartOfWeek
. For example, if you want to find the next monday relative todate
you 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.
-