public class DateUtils extends Object
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.
Constructor and Description |
---|
DateUtils() |
Modifier and Type | Method and Description |
---|---|
static long |
addDays(long time,
int amount)
Adds
amount days to time and returns
the resulting time. |
static Date |
endOfDay(Date date)
Returns the last millisecond of the specified date.
|
static long |
endOfDayInMillis(long date)
Returns the last millisecond of the specified date.
|
private static long |
getDay(long date,
int startOfWeek,
int increment) |
static int |
getDayOfWeek(long date)
Returns the day of the week.
|
static int |
getDaysDiff(long t1,
long t2)
Returns the number of days difference between
t1 and
t2 . |
static int |
getDaysDiff(long t1,
long t2,
boolean checkOverflow)
Returns the number of days difference between
t1 and
t2 . |
static long |
getEndOfMonth(long date)
Returns the date corresponding to the end of the month.
|
private static long |
getMonth(long date,
int increment) |
static long |
getNextDay(long date,
int startOfWeek)
Returns the first day after
date that has the
day of week matching startOfWeek . |
static long |
getNextMonth(long date)
Returns the next month.
|
static long |
getPreviousDay(long date,
int startOfWeek)
Returns the first day before
date that has the
day of week matching startOfWeek . |
static long |
getPreviousMonth(long date)
Returns the previous month.
|
static long |
getStartOfMonth(long date)
Returns the date corresponding to the start of the month.
|
private static long |
incrementMonth(long date,
int increment) |
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 Date |
nextDay(Date date)
Returns the day after
date . |
static long |
nextDay(long date)
Returns the day after
date . |
static long |
nextWeek(long date)
Returns the week after
date . |
static long |
previousDay(long date)
Returns the day before
date . |
static long |
previousWeek(long date)
Returns the week before
date . |
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.
|
public DateUtils()
public static Date endOfDay(Date date)
date
- Date to calculate end of day fromdate
public static Date startOfDay(Date date)
date
- Date used in calculating start of daydate
public static long startOfDayInMillis(long date)
date
- long used in calculating start of daydate
public static long endOfDayInMillis(long date)
date
- long to calculate end of day fromdate
public static Date nextDay(Date date)
date
.date
- Date used in calculating next daydate
.public static long addDays(long time, int amount)
amount
days to time
and returns
the resulting time.time
- Base timeamount
- Amount of increment.public static long nextDay(long date)
date
.date
- Date used in calculating next daydate
.public static long nextWeek(long date)
date
.date
- Date used in calculating next weekdate
.public static int getDaysDiff(long t1, long t2, boolean checkOverflow)
t1
and
t2
.t1
- Time 1t2
- Time 2checkOverflow
- indicates whether to check for overflowstart
and end
public static int getDaysDiff(long t1, long t2)
t1
and
t2
.t1
- Time 1t2
- Time 2start
and end
public static boolean isFirstOfYear(long date)
date
- date to check in millistrue
if date corresponds to the first
day of a yearDate.getTime()
public static boolean isFirstOfMonth(long date)
date
- date to check in millistrue
if date corresponds to the first
day of a monthDate.getTime()
public static long previousDay(long date)
date
.date
- Date used in calculating previous daydate
.public static long previousWeek(long date)
date
.date
- Date used in calculating previous weekdate
.public static long getPreviousDay(long date, int startOfWeek)
date
that has the
day of week matching startOfWeek
. For example, if you
want to find the previous monday relative to date
you
would call getPreviousDay(date, Calendar.MONDAY)
.date
- Base datestartOfWeek
- Calendar constant correspoding to start of week.public static long getNextDay(long date, int startOfWeek)
date
that has the
day of week matching startOfWeek
. For example, if you
want to find the next monday relative to date
you
would call getPreviousDay(date, Calendar.MONDAY)
.date
- Base datestartOfWeek
- Calendar constant correspoding to start of week.private static long getDay(long date, int startOfWeek, int increment)
public static long getPreviousMonth(long date)
date
- Base datepublic static long getNextMonth(long date)
date
- Base dateprivate static long incrementMonth(long date, int increment)
public static long getStartOfMonth(long date)
date
- Base datepublic static long getEndOfMonth(long date)
date
- Base dateprivate static long getMonth(long date, int increment)
public static int getDayOfWeek(long date)
date
- dateWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses