public final class DateHelper extends Object
Modifier and Type | Field and Description |
---|---|
static Date |
DAY_END_TIME
is 24:00
|
static Date |
DAY_START_TIME
is 00:00
|
static Date |
INFINITE_FUTURE
Value
new Date(Long.MAX) doesn't work because the value will be truncated when it is saved into
database. |
static Date |
INFINITE_FUTURE_DATE |
static Date |
INFINITE_FUTURE_TIME |
static Date |
INFINITE_PAST
Value
new Date(Long.MIN) doesn't work because the value will be truncated when it is saved into
database. |
static Date |
INFINITE_PAST_DATE |
static Date |
INFINITE_PAST_TIME |
static String |
ISO_DATE_FORMAT
The ISO format for a date.
|
static String |
ISO_DATETIME_FORMAT
The ISO format for a date with time (until seconds).
|
static String |
ISO_TIME_FORMAT
The ISO format for time (until seconds).
|
Constructor and Description |
---|
DateHelper() |
Modifier and Type | Method and Description |
---|---|
static void |
addDaysToDate(Date date,
int noOfDays) |
static void |
addMonthToDate(Date date,
int monthAmount) |
static void |
addTimeSpanToDate(Date date,
TimeSpan timeSpan) |
static void |
addYearToDate(Date date,
int yearAmount) |
static boolean |
after(Date baseDate,
Date compareDate)
Deprecated.
|
static boolean |
before(Date baseDate,
Date compareDate)
Deprecated.
|
static boolean |
dateAfter(Date baseDate,
Date compareDate) |
static boolean |
dateAfterOrEqual(Date baseDate,
Date compareDate) |
static boolean |
dateBefore(Date baseDate,
Date compareDate) |
static boolean |
dateBeforeOrEqual(Date baseDate,
Date compareDate) |
static boolean |
dateEquals(Date d1,
Date d2)
Compares two dates for equality based on their dates only.
|
static boolean |
equals(Date d1,
Date d2)
Deprecated.
|
static Date |
futureInfinite() |
static Calendar |
getCalendarInstance() |
static Date |
getDate(Calendar calendar)
|
static Date |
getDate(Date date)
Extracts only the date part of
Date . |
static Date |
getDate(int year,
int month,
int day)
Creates a
Date out of the given parameters. |
static int |
getDayOfMonth(Date date) |
static Date |
getEndOfTheDay(Date date)
Deprecated.
|
static int |
getMonth(Date date) |
static Date |
getStartOfTheDay(Date date)
Deprecated.
|
static Date |
getTime(Calendar calendar)
|
static Date |
getTime(Date date)
Extracts only the date part of
Date . |
static Date |
getTime(int hour,
int min,
int sec) |
static int |
getYear(Date date) |
static boolean |
isAnySet(Date date) |
static boolean |
isDateBetween(Date date,
Date from,
Date to)
Returns true if the given
date is between the from and the to date (from
and to included). |
static boolean |
isDateSet(Date date) |
static boolean |
isDateTimeSet(Date date)
Deprecated.
|
static Date |
isoDateStringToDate(String isoDateString) |
static Date |
isoDateTimeStringToDate(String isoDateString) |
static boolean |
isTimeSet(Date date) |
static boolean |
isWithinBounds(Date date)
Checks if the given date is within the allowed bounds, i.e.
|
static Date |
now()
Deprecated.
|
static Date |
pastInfinite() |
static Date |
stringToDate(String date)
Deprecated.
|
static boolean |
timeAfter(Date base,
Date compare) |
static boolean |
timeAfterOrEqual(Date base,
Date compare) |
static boolean |
timeBefore(Date base,
Date compare) |
static boolean |
timeBeforeOrEqual(Date base,
Date compare) |
static boolean |
timeEquals(Date d1,
Date d2)
Compares two times for equality based on their times only.
|
static Date |
today() |
static Date |
tomorrow()
Returns the
Date of tomorrow with the current time. |
static Date |
tomorrow(Date date)
Returns the given
Date plus one day with the same time. |
static Date |
yesterday()
Returns the
Date of yesterday with the current time. |
static Date |
yesterday(Date date)
Returns the given
Date minus one day with the same time. |
public static final String ISO_DATE_FORMAT
public static final String ISO_DATETIME_FORMAT
public static final String ISO_TIME_FORMAT
00:00:00
to 23:59:59
.public static final Date INFINITE_PAST
new Date(Long.MIN)
doesn't work because the value will be truncated when it is saved into
database. The used date is 1 January 0001
.public static final Date INFINITE_PAST_DATE
public static final Date INFINITE_PAST_TIME
public static final Date INFINITE_FUTURE
new Date(Long.MAX)
doesn't work because the value will be truncated when it is saved into
database. The used date is 31 December 2999
. The time measure is cyclic, so, we cannot flag a
specific value. So, we use a hack and put a flag on the millisecond value.public static final Date INFINITE_FUTURE_DATE
public static final Date INFINITE_FUTURE_TIME
public static final Date DAY_START_TIME
public static final Date DAY_END_TIME
public static Calendar getCalendarInstance()
public static Date getDate(Date date)
date
- Is the date to manage.public static Date getDate(Calendar calendar)
calendar
- Is the calendar to convert.public static Date getTime(Date date)
date
- Is the date to manage.public static Date getTime(Calendar calendar)
calendar
- Is the calendar to convert.public static Date getDate(int year, int month, int day)
Date
out of the given parameters.year
- Is the year part of the date.month
- Is the month part of the date.day
- Is the day part of the date.public static Date getTime(int hour, int min, int sec)
public static boolean isWithinBounds(Date date)
INFINITE_PAST
and
INFINITE_FUTURE
.date
- the date to checktrue
if within boundspublic static Date pastInfinite()
Date
1 January 0001 00:00:00.666
.public static Date futureInfinite()
Date
31 December 2999 00:00:00.666
.public static Date yesterday(Date date)
Date
minus one day with the same time.date
- Is the given date.public static Date yesterday()
Date
of yesterday with the current time.public static Date tomorrow(Date date)
Date
plus one day with the same time.date
- Is the given date.public static Date tomorrow()
Date
of tomorrow with the current time.public static boolean isDateBetween(Date date, Date from, Date to)
date
is between the from
and the to
date (from
and to included).date
- Is the date to test.from
- Is the region start date.to
- Is the region stop date.date
is between the from
and the to
date
(from and to included).public static boolean dateEquals(Date d1, Date d2)
d1
- base dated2
- the date to compare withtrue
if the objects are the same; false
otherwise.public static boolean timeEquals(Date d1, Date d2)
d1
- base timed2
- the time to compare withtrue
if the objects are the same; false
otherwise.public static boolean isDateSet(Date date)
public static boolean isTimeSet(Date date)
public static boolean isAnySet(Date date)
public static int getDayOfMonth(Date date)
public static int getMonth(Date date)
public static int getYear(Date date)
public static void addDaysToDate(Date date, int noOfDays)
public static void addMonthToDate(Date date, int monthAmount)
public static void addYearToDate(Date date, int yearAmount)
@Deprecated public static Date stringToDate(String date)
@Deprecated public static boolean isDateTimeSet(Date date)
@Deprecated public static boolean after(Date baseDate, Date compareDate)
baseDate
- base datecompareDate
- the date to compare withtrue
if and only if the instant represented by this Date object is strictly later
than the instant represented by when; false
otherwise.@Deprecated public static boolean equals(Date d1, Date d2)
d1
- base dated2
- the date to compare withtrue
if the objects are the same; false
otherwise.@Deprecated public static boolean before(Date baseDate, Date compareDate)
baseDate
- base datecompareDate
- the date to compare withtrue
if and only if the instant of time represented by this Date object is strictly
earlier than the instant represented by when; false
otherwise.@Deprecated public static Date now()
@Deprecated public static Date getStartOfTheDay(Date date)
date
- date to process@Deprecated public static Date getEndOfTheDay(Date date)
date
- date to processCopyright © 2021. All rights reserved.