public class DateUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
DateUtils.DateFields |
| Modifier and Type | Field and Description |
|---|---|
static long |
DAY_IN_MS |
static int |
FORMAT_HUMAN_READABLE_DAYS_FROM_TODAY |
static int |
FORMAT_HUMAN_READABLE_SHORT |
static int |
FORMAT_ISO8601 |
static int |
FORMAT_TIMESTAMP_HTTP
RFC 822
|
static int |
FORMAT_TIMESTAMP_SUFFIX |
| Constructor and Description |
|---|
DateUtils() |
| Modifier and Type | Method and Description |
|---|---|
static Date |
dateAdd(Date d,
int n)
add n days to date d
|
static int |
dateDiff(Date a,
Date b)
return the number of days between a and b, positive if b is later than a
|
static int |
daysInMonth(int month,
int year)
Returns the number of days in the month given for
a given year.
|
static int |
daysSinceEpoch(Date date) |
static double |
decimalTimeOfLocalDay(Date d)
Returns the fractional time within the local day.
|
static String |
format(Date d,
String format) |
static String |
format(DateUtils.DateFields f,
String format) |
static String |
formatDate(Date d,
int format) |
static String |
formatDateTime(Date d,
int format) |
static String |
formatDateToTimeStamp(Date date) |
static String |
formatTime(Date d,
int format) |
static Double |
fractionalDaysSinceEpoch(Date a) |
static String |
get24HourTimeFromDate(Date d) |
static Date |
getDate(DateUtils.DateFields f) |
static Date |
getDate(DateUtils.DateFields f,
String timezone) |
static Date |
getDate(int year,
int month,
int day) |
static Date |
getDateFromString(String value) |
static Date |
getDateTimeFromString(String value) |
static DateUtils.DateFields |
getFields(Date d) |
static DateUtils.DateFields |
getFields(Date d,
String timezone) |
static int |
getMonthsDifference(Date earlierDate,
Date laterDate)
Gets the number of months separating the two dates.
|
static Date |
getPastPeriodDate(Date ref,
String type,
String start,
boolean beginning,
boolean includeToday,
int nAgo)
Creates a Date object representing the amount of time between the
reference date, and the given parameters.
|
static String |
getShortStringValue(Date val) |
static String |
getXMLStringValue(Date val) |
static String |
intPad(int n,
int pad)
Converts an integer to a string, ensuring that the string
contains a certain number of digits
|
static boolean |
isLeap(int year)
Determines whether a year is a leap year in the
proleptic Gregorian calendar.
|
static Date |
parseDate(String str) |
static Date |
parseDateTime(String str) |
static Date |
parseTime(String str) |
static Date |
parseTimeWithFixedDate(String str,
DateUtils.DateFields fields) |
static Date |
roundDate(Date d) |
static List<String> |
split(String str,
String delimiter,
boolean combineMultipleDelimiters)
Tokenizes a string based on the given delimiter string
|
static boolean |
stringContains(String string,
String substring) |
static Date |
today() |
public static final int FORMAT_ISO8601
public static final int FORMAT_HUMAN_READABLE_SHORT
public static final int FORMAT_HUMAN_READABLE_DAYS_FROM_TODAY
public static final int FORMAT_TIMESTAMP_SUFFIX
public static final int FORMAT_TIMESTAMP_HTTP
public static final long DAY_IN_MS
public static DateUtils.DateFields getFields(Date d)
public static DateUtils.DateFields getFields(Date d, String timezone)
public static Date getDate(DateUtils.DateFields f)
public static Date getDate(DateUtils.DateFields f, String timezone)
public static String format(DateUtils.DateFields f, String format)
public static Date parseTimeWithFixedDate(String str, DateUtils.DateFields fields)
public static Date getDate(int year, int month, int day)
public static Date roundDate(Date d)
public static Date today()
public static double decimalTimeOfLocalDay(Date d)
d - public static int daysInMonth(int month,
int year)
month - The month to be testedyear - The year in which the month is to be testedpublic static boolean isLeap(int year)
year - The year to be testedpublic static Date getPastPeriodDate(Date ref, String type, String start, boolean beginning, boolean includeToday, int nAgo)
ref - The starting reference datetype - "week", or "month", representing the time period which is to be returned.start - "sun", "mon", ... etc. representing the start of the time period.beginning - true=return first day of period, false=return last day of periodincludeToday - Whether to include the current date in the returned calculationnAgo - How many periods ago. 1=most recent period, 0=period in progresspublic static int getMonthsDifference(Date earlierDate, Date laterDate)
earlierDate - The earlier date, chronologicallylaterDate - The later date, chronologicallypublic static int daysSinceEpoch(Date date)
date - the date object to be analyzedpublic static int dateDiff(Date a, Date b)
a - b - public static List<String> split(String str, String delimiter, boolean combineMultipleDelimiters)
str - The string to be splitdelimiter - The delimeter to be usedpublic static String intPad(int n, int pad)
n - The integer to be convertedpad - The length of the string to be returnedCopyright © 2023. All rights reserved.