public final class DateUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static Comparator<Calendar> |
CALENDAR_TIMES_COMPARATOR
Compares calendar times (hours, minutes, seconds and milliseconds) and returns
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
|
static Date |
FUTURE
A fixed date way into the future.
|
| Modifier and Type | Method and Description |
|---|---|
static Date |
addDays(Date in,
int days) |
static Date |
addMinutes(Date in,
int minutes) |
static Date |
addMonths(Date in,
int months) |
static Date |
addYears(Date in,
int years) |
static boolean |
between(Date start,
Date end,
Date v) |
static Date |
calculateDurationEndInSec(Date start,
int durationInSeconds) |
static void |
clearTime(Calendar cal)
Clears the entire time portion of a Calendar.
|
static Date |
convertToDate(String input,
String dateFormat)
Parses input String to
Date class, according to dateFormat argument. |
static Date |
convertToDate(String input,
String dateFormat,
boolean lenient)
Parses input String to
Date class, according to dateFormat argument. |
static Date |
dateFor(int year,
int month,
int day) |
static Date |
dateFor(int year,
int month,
int day,
int hour,
int minute,
int sec,
int mils) |
static Date |
dateFromDateTime(Date coredate,
String timestring)
Decraps the separate date / time found in the VP database into a normal date containing
the time.
|
static long |
decodeTime(String timestring)
Decodes a time string, encoded as hh:mm:ss.mmmm where ss.mmmm are optional.
|
static int |
deltaInDays(Date start,
Date end)
Get the difference in number of days between the specified dates.
|
static int |
deltaMonths(Date start,
Date end) |
static Date |
dumbEndOfDayDate(Date dt)
INTERNAL DAO USE ONLY -- This returns a date/ which ends at
23:59 of the day passed.
|
static String |
encodeTimeInMS(long millis,
int nfields,
boolean shortest)
Quick conversion of time to a string for presentation pps.
|
static String |
extractTimeString(Date dt,
int size)
Extracts the dumb time field from a date.
|
static String |
formatSafe(Date date,
DateFormat format)
Returns format for specified date and formatter.
|
static Calendar |
getCalendar()
GregorianCalendarFixDutchTime fixes missing date-time in the GregorianCalendar for dutch locale
when validating those missing date-times the next valid time will be returned instead of generating an error
|
static Calendar |
getCalendar(Locale aLocale)
GregorianCalendarFixDutchTime fixes missing date-time in the GregorianCalendar for dutch locale
when validating those missing date-times the next valid time will be returned instead of generating an error
|
static Date |
getFirstDayOfNextMonth(Date dt)
Gets the first day of the next month for the date specified in parameter.
|
static Calendar |
getIsoCalendarForYearAndWeek(int year,
int weekOfYear)
Returns ISO calendar with specified year and week.
|
static int |
getMonth(Date date)
Returns month for Date.
|
static long |
getTime(Date from,
TimeUnit unit)
Extract the time fields from a date value and return as a value
in the specified unit.
|
static int |
getYear(Date date)
Returns year for Date.
|
static Date |
incrementDate(Date dt,
int field,
int amount)
Returns date incremented for specified value.
|
static boolean |
isFutureIndeterminate(Date date)
Return T if the date is a indeterminate future date.
|
static boolean |
isTestDateSet() |
static boolean |
isWeekend(Calendar cal) |
static void |
main(String[] args) |
static Date |
now() |
static boolean |
overlaps(Date s1,
Date e1,
Date s2,
Date e2) |
static void |
setDate(Calendar cal,
int year,
int month,
int day) |
static Date |
setDateOnly(Date finisheddate,
Date dt)
Updates the date part of a date only, leaving the time part unaltered.
|
static void |
setSystemTestDate(Date now) |
static void |
setTestDate(Date now) |
static void |
setTime(Calendar cal,
int h,
int m,
int s,
int ms) |
static Date |
sqlToUtilDate(Date sqlDate)
Converts java.sql.Date to java.util.Date.
|
static Date |
tomorrow(Date dt)
Calculates the date for 0:00 the day after (tomorrow).
|
static Date |
truncateCeil(Date date)
Truncate a date to be at 0:00 by ceiling the time.
|
static Date |
truncateDate(Date dt) |
static void |
truncateDate(Date dest,
Date dt) |
static Date |
truncateSeconds(Date dt) |
static Date |
yearStartDate(int year) |
public static final Comparator<Calendar> CALENDAR_TIMES_COMPARATOR
public static long getTime(@Nonnull Date from, @Nonnull TimeUnit unit)
from - unit - @Nonnull public static Date truncateCeil(@Nonnull Date date)
date - public static Date dateFromDateTime(Date coredate, String timestring)
coredate - timestring - public static String encodeTimeInMS(long millis, int nfields, boolean shortest)
millis - Time in millis.nfields - The number of fields to show: 1 = hours only, 2= hh:mm, 3=h:mm:ss. Warning:
the fields that are not shown do not "round up" the shown fields! So if you
use nfields=1 for 18:45 the hour shown would be 18, not 19!shortest - When set this truncates the time display when components are zero. So for
18:00:0) this would render '18'; for 18:21:00 this would render 18:21.public static long decodeTime(String timestring)
time - public static String extractTimeString(Date dt, int size)
dt - public static Date incrementDate(Date dt, int field, int amount)
dt - field - see Calendar.add(int, int)amount - see Calendar.add(int, int)public static Date tomorrow(Date dt)
ts - public static Date dumbEndOfDayDate(Date dt)
dt - public static void clearTime(Calendar cal)
cal - public static Date yearStartDate(int year)
public static Date calculateDurationEndInSec(Date start, int durationInSeconds)
public static Date dateFor(int year, int month, int day)
public static void setDate(Calendar cal, int year, int month, int day)
public static Date dateFor(int year, int month, int day, int hour, int minute, int sec, int mils)
public static void setTime(Calendar cal, int h, int m, int s, int ms)
public static void main(String[] args)
public static Date setDateOnly(Date finisheddate, Date dt)
finisheddate - dt - public static Date getFirstDayOfNextMonth(Date dt)
dt - public static int deltaInDays(Date start, Date end)
start - end - public static Calendar getIsoCalendarForYearAndWeek(int year, int weekOfYear)
year - weekOfYear - @Nonnull public static Date convertToDate(@Nonnull String input, @Nonnull String dateFormat, boolean lenient) throws ParseException
Date class, according to dateFormat argument.input - - input string to be parseddateFormat - - to what format should the date be parsedlenient - - specify whether or not date/time parsing is to be lenientParseException@Nonnull public static Date convertToDate(@Nonnull String input, @Nonnull String dateFormat) throws ParseException
Date class, according to dateFormat argument. Lenient is true.input - dateFormat - ParseExceptionpublic static int getYear(@Nonnull Date date)
date - public static int getMonth(@Nonnull Date date)
date - public static Date sqlToUtilDate(@Nullable Date sqlDate)
sqlDate - @Nonnull public static String formatSafe(@Nullable Date date, @Nonnull DateFormat format)
date - format - public static boolean isTestDateSet()
@Nonnull public static Calendar getCalendar()
@Nonnull public static Calendar getCalendar(@Nonnull Locale aLocale)
aLocale - Copyright © 2017 etc.to. All rights reserved.