public class DateHelper extends Object
| Constructor and Description |
|---|
DateHelper() |
| Modifier and Type | Method and Description |
|---|---|
static Date |
add(Date date,
int diff,
TimeUnit unit)
Adds the specified amount of time to the given
date. |
static boolean |
is(Date firstDate,
TimeComparator comparator,
Date secondDate)
Evaluates whether
firstDate satisfies comparator when compared to secondDate. |
static Date |
minus(Date date,
int diff,
TimeUnit unit)
Subtracts the specified amount of time from the given
date. |
static Date |
now()
Syntax sugar.
|
static String |
now(String pattern)
Returns string representation of the current time according to the given
pattern. |
static Date |
toDate(String str,
String pattern)
|
static long |
toMilliseconds(long input,
TimeUnit unit)
Converts
input to milliseconds with respect to the given unit. |
static String |
toString(Date date,
String pattern)
Returns string representation of the given
date and formats it according to the given
pattern. |
public static Date add(Date date, int diff, TimeUnit unit)
date.public static Date minus(Date date, int diff, TimeUnit unit)
date.public static boolean is(Date firstDate, TimeComparator comparator, Date secondDate)
firstDate satisfies comparator when compared to secondDate.firstDate - of type Datecomparator - of type TimeComparatorsecondDate - of type DatefirstDate satisfies comparator when compared to secondDate.
firstDate and secondDate are null and TimeComparator.EQUAL_TO is not usedfirstDate and secondDate are null and TimeComparator.NOT_EQUAL_TO is usedfirstDate and secondDate are not null and TimeComparator.NOT_EQUAL_TO is usedfirstDate or secondDate is nullcomparator is nullfirstDate does not satisfy comparator when compared to secondDate public static String now(String pattern)
pattern.pattern - must conform to the specifications of DateTimeFormatnow(),
DateTimeFormatpublic static Date toDate(String str, String pattern)
str - to be parsedpattern - must conform to the specifications of DateTimeFormat.
Common patterns can be found in CommonDateTimePatterns.Date with the parsed value if neither str nor
pattern is blank, otherwise returns nullpublic static String toString(Date date, String pattern)
date and formats it according to the given
pattern.date - to be converted to Stringpattern - must conform to the specifications of DateTimeFormat.
Common patterns can be found in CommonDateTimePatterns.date. Never returns null.public static long toMilliseconds(long input,
TimeUnit unit)
input to milliseconds with respect to the given unit.input - time, paired with unitunit - of type TimeUnit. Passing null will return the input itself,
without converting it into millisecondsinput.Copyright © 2018. All rights reserved.