public final class DateUtil
extends Object
CalendarUtil
Modifier and Type | Method and Description |
---|---|
static Date |
addDays(Date date,
int days)
Add the given amount of days to the given date.
|
static Date |
addHours(Date date,
int hours)
Add the given amount of hours to the given date.
|
static Date |
addMillis(Date date,
int millis)
Add the given amount of millis to the given date.
|
static Date |
addMinutes(Date date,
int minutes)
Add the given amount of minutes to the given date.
|
static Date |
addMonths(Date date,
int months)
Add the given amount of months to the given date.
|
static Date |
addSeconds(Date date,
int seconds)
Add the given amount of seconds to the given date.
|
static Date |
addYears(Date date,
int years)
Add the given amount of years to the given date.
|
static String |
determineDateFormat(String dateString)
Determine SimpleDateFormat pattern matching with the given date string.
|
static int |
elapsedDays(Date before,
Date after)
Retrieve the amount of elapsed days between the two given dates.
|
static int |
elapsedHours(Date before,
Date after)
Retrieve the amount of elapsed hours between the two given dates.
|
static long |
elapsedMillis(Date before,
Date after)
Retrieve the amount of elapsed milliseconds between the two given dates.
|
static int |
elapsedMinutes(Date before,
Date after)
Retrieve the amount of elapsed minutes between the two given dates.
|
static int |
elapsedMonths(Date before,
Date after)
Retrieve the amount of elapsed months between the two given dates.
|
static int |
elapsedSeconds(Date before,
Date after)
Retrieve the amount of elapsed seconds between the two given dates.
|
static int[] |
elapsedTime(Date before,
Date after)
Calculate the total of elapsed time from years up to seconds between the
two given dates.
|
static int |
elapsedYears(Date before,
Date after)
Retrieve the amount of elapsed years between the two given dates.
|
static boolean |
isValidDate(String dateString)
Checks whether the actual date of the given date string is valid.
|
static boolean |
isValidDate(String dateString,
String dateFormat)
Checks whether the actual date of the given date string is valid based on
the given date format pattern.
|
static Date |
parse(String dateString)
Parse the given date string to date object and return a date instance
based on the given date string.
|
static Date |
parse(String dateString,
String dateFormat)
Validate the actual date of the given date string based on the given date
format pattern and return a date instance based on the given date string.
|
static Date |
parseDate(String dateString)
Parses the date.
|
static Date |
parseDate(String dateString,
String format)
Parses the date.
|
static boolean |
sameDay(Date one,
Date two)
Returns true if the two given dates are dated on the same year,
month and day.
|
static boolean |
sameHour(Date one,
Date two)
Returns true if the two given dates are dated on the same year,
month, day and hour.
|
static boolean |
sameMinute(Date one,
Date two)
Returns true if the two given dates are dated on the same year,
month, day, hour and minute.
|
static boolean |
sameMonth(Date one,
Date two)
Returns true if the two given dates are dated on the same year
and month.
|
static boolean |
sameSecond(Date one,
Date two)
Returns true if the two given dates are dated on the same year,
month, day, hour, minute and second.
|
static boolean |
sameYear(Date one,
Date two)
Returns true if the two given dates are dated on the same year.
|
static Calendar |
toCalendar(Date date)
Convert the given date to a Calendar object.
|
static Calendar |
toCalendar(Date date,
TimeZone timeZone)
Convert the given date to a Calendar object with the given timezone.
|
public static Date addDays(Date date, int days)
CalendarUtil.addDays(Calendar, int)
and then converts back to date.date
- The date to add the given amount of days to.days
- The amount of days to be added to the given date. Negative
values are also allowed, it will just go back in time.public static Date addHours(Date date, int hours)
CalendarUtil.addHours(Calendar, int)
and then converts back to date.date
- The date to add the given amount of hours to.hours
- The amount of hours to be added to the given date. Negative
values are also allowed, it will just go back in time.public static Date addMillis(Date date, int millis)
date
- The date to add the given amount of millis to.millis
- The amount of millis to be added to the given date. Negative
values are also allowed, it will just go back in time.CalendarUtil.addMillis(Calendar, int)
and then
converts back to date.public static Date addMinutes(Date date, int minutes)
date
- The date to add the given amount of minutes to.minutes
- The amount of minutes to be added to the given date. Negative
values are also allowed, it will just go back in time.CalendarUtil.addMinutes(Calendar, int)
and then
converts back to date.public static Date addMonths(Date date, int months)
date
- The date to add the given amount of months to.months
- The amount of months to be added to the given date. Negative
values are also allowed, it will just go back in time.CalendarUtil.addMonths(Calendar, int)
and then
converts back to date.public static Date addSeconds(Date date, int seconds)
date
- The date to add the given amount of seconds to.seconds
- The amount of seconds to be added to the given date. Negative
values are also allowed, it will just go back in time.CalendarUtil.addSeconds(Calendar, int)
and then
converts back to date.public static Date addYears(Date date, int years)
CalendarUtil.addYears(Calendar, int)
and then converts back to date.date
- The date to add the given amount of years to.years
- The amount of years to be added to the given date. Negative
values are also allowed, it will just go back in time.public static String determineDateFormat(String dateString)
dateString
- The date string to determine the SimpleDateFormat pattern for.SimpleDateFormat
public static int elapsedDays(Date before, Date after)
before
- The first date with expected date before the second date.after
- The second date with expected date after the first date.CalendarUtil.elapsedDays(Calendar, Calendar)
.CalendarUtil.elapsedDays(Calendar, Calendar)
public static int elapsedHours(Date before, Date after)
before
- The first date with expected date before the second date.after
- The second date with expected date after the first date.CalendarUtil.elapsedHours(Calendar, Calendar)
.CalendarUtil.elapsedHours(Calendar, Calendar)
public static long elapsedMillis(Date before, Date after)
before
- The first date with expected date before the second date.after
- The second date with expected date after the first date.CalendarUtil.elapsedMillis(Calendar, Calendar)
.CalendarUtil.elapsedMillis(Calendar, Calendar)
public static int elapsedMinutes(Date before, Date after)
before
- The first date with expected date before the second date.after
- The second date with expected date after the first date.CalendarUtil.elapsedMinutes(Calendar, Calendar)
.CalendarUtil.elapsedMinutes(Calendar, Calendar)
public static int elapsedMonths(Date before, Date after)
before
- The first date with expected date before the second date.after
- The second date with expected date after the first date.CalendarUtil.elapsedMonths(Calendar, Calendar)
.CalendarUtil.elapsedMonths(Calendar, Calendar)
public static int elapsedSeconds(Date before, Date after)
before
- The first date with expected date before the second date.after
- The second date with expected date after the first date.CalendarUtil.elapsedSeconds(Calendar, Calendar)
.CalendarUtil.elapsedSeconds(Calendar, Calendar)
public static int[] elapsedTime(Date before, Date after)
before
- The first date with expected date before the second date.after
- The second date with expected date after the first date.CalendarUtil.elapsedTime(Calendar, Calendar)
.CalendarUtil.elapsedTime(Calendar, Calendar)
public static int elapsedYears(Date before, Date after)
before
- The first date with expected date before the second date.after
- The second date with expected date after the first date.CalendarUtil.elapsedYears(Calendar, Calendar)
.CalendarUtil.elapsedYears(Calendar, Calendar)
public static boolean isValidDate(String dateString)
determineDateFormat(String)
to
determine the SimpleDateFormat pattern to be used for parsing.dateString
- The date string.public static boolean isValidDate(String dateString, String dateFormat)
dateString
- The date string.dateFormat
- The date format pattern which should respect the
SimpleDateFormat rules.SimpleDateFormat
public static Date parse(String dateString) throws ParseException
dateString
- The date string to be parsed to date object.ParseException
- If the date format pattern of the given date string is
unknown, or if the given date string or its actual date is
invalid based on the date format pattern.
determineDateFormat(String)
to determine the
SimpleDateFormat pattern to be used for parsing.public static Date parse(String dateString, String dateFormat) throws ParseException
dateString
- The date string.dateFormat
- The date format pattern which should respect the
SimpleDateFormat rules.ParseException
- If the given date string or its actual date is invalid based
on the given date format pattern.SimpleDateFormat
public static Date parseDate(String dateString, String format)
dateString
- the date stringformat
- the formatpublic static Date parseDate(String dateString)
dateString
- the date stringpublic static boolean sameDay(Date one, Date two)
one
- The one date.two
- The other date.CalendarUtil.sameDay(Calendar, Calendar)
.CalendarUtil.sameDay(Calendar, Calendar)
public static boolean sameHour(Date one, Date two)
CalendarUtil.sameHour(Calendar, Calendar)
.one
- The one date.two
- The other date.CalendarUtil.sameHour(Calendar, Calendar)
public static boolean sameMinute(Date one, Date two)
CalendarUtil.sameMinute(Calendar, Calendar)
.one
- The one date.two
- The other date.CalendarUtil.sameMinute(Calendar, Calendar)
public static boolean sameMonth(Date one, Date two)
one
- The one date.two
- The other date.CalendarUtil.sameMonth(Calendar, Calendar)
.CalendarUtil.sameMonth(Calendar, Calendar)
public static boolean sameSecond(Date one, Date two)
CalendarUtil.sameSecond(Calendar, Calendar)
.one
- The one date.two
- The other date.CalendarUtil.sameSecond(Calendar, Calendar)
public static boolean sameYear(Date one, Date two)
one
- The one date.two
- The other date.CalendarUtil.sameYear(Calendar, Calendar)
.CalendarUtil.sameYear(Calendar, Calendar)
public static Calendar toCalendar(Date date)
date
- The date to be converted to Calendar.public static Calendar toCalendar(Date date, TimeZone timeZone)
date
- The date to be converted to Calendar.timeZone
- The timezone to be set in the Calendar.Copyright © 2010-2020 Toolsverse. All Rights Reserved.