public class DateUtil extends Object
Note:
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_PATTERN |
static String |
MONTH_PATTERN |
| Constructor and Description |
|---|
DateUtil() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
between(Date myDate,
Date beforeDate,
Date afterDate)
Check if the first date in argument is included between the two other
dates.
|
static Date |
createDate(int dd,
int mm,
int yy)
Create a new date from day, month and year (French version).
|
static Date |
createDate(int s,
int m,
int h,
int dd,
int mm,
int yy)
Create a new date from day, month and year (French version).
|
static Date |
createDateAfterToday(int ddStep,
int mmStep,
int yyStep)
Create a new date after the current date (today) with modification on day, month and year.
|
static boolean |
currentPeriod(Date beforeDate,
Date afterDate)
Check if the current date is between the two dates in argument.
|
static String |
formatDate(Date date,
String pattern)
Format a date using the pattern in argument.
|
static String |
formatDate(Date date,
String pattern,
Locale locale) |
static int |
getAge(Date birthDate)
Get the age of a person born on the date in argument.
|
static Date |
getDateAndTime(Date day,
Date time,
boolean useSecond,
boolean useMiliSecond)
Créer la date qui utilise le jour donné dans
day et l'heure
donnée dans time. |
static Date |
getDay(Date date)
Enleve les données des heures (hour, minute, second, milli = 0).
|
static Calendar |
getDefaultCalendar(Date date)
Get the calendar corresponding to the
date. |
static int |
getDifferenceInDays(Date beginDate,
Date endDate)
Do the difference between the two dates in argument.
|
static int |
getDifferenceInHours(Date beginDate,
Date endDate)
Do the difference between the two dates in argument.
|
static int |
getDifferenceInMinutes(Date beginDate,
Date endDate)
Do the difference between the two dates in argument.
|
static int |
getDifferenceInMonths(Date beginDate,
Date endDate)
Do the difference between the two dates in argument.
|
static int |
getDifferenceInSeconds(Date beginDate,
Date endDate)
Do the difference between the two dates in argument.
|
static Date |
getEndOfDay(Date date)
Positionne une date sur la fin d'un jour
|
static int |
getMonth(Date date)
Get the month value from a date (between 0 and 11).
|
static String |
getMonthLibelle(int monthNumber)
Get libelle of the month corresponding to the number given in argument.
|
static String |
getMonthLibelle(int monthNumber,
Locale locale)
Get libelle of the month corresponding to the number given in argument.
|
static Date |
getTime(Date dayTime,
boolean useSecond,
boolean useMiliSecond)
Créer la date qui utilise uniquement l'heure
donnée dans
dayTime. |
static Date |
getYesterday(Date date)
Get the date before today
|
static Date |
parseDate(String date,
String pattern)
Parse a date using the pattern in argument.
|
static Date |
setFirstDayOfMonth(Date date)
Set the first day of month to the date in argument.
|
static Date |
setFirstDayOfYear(Date date)
Set the first day of year to the date in argument.
|
static Date |
setLastDayOfMonth(Date date)
Set the last day of month to the date in argument.
|
static Date |
setLastDayOfYear(Date date)
Set the last day of year to the date in argument.
|
static Date |
setMaxTimeOfDay(Date date)
Set the max time of the day.
|
static Date |
setMinTimeOfDay(Date date)
Set the min time of the day : 00:00:00.000.
|
static Date |
truncateToDayOfWeek(Date date)
Truncate a date to its week (to monday).
|
public static final String DEFAULT_PATTERN
public static final String MONTH_PATTERN
public static String formatDate(Date date, String pattern)
date - the date to formatpattern - the pattern to useDateFormatpublic static Date parseDate(String date, String pattern) throws ParseException
date - the String to parsepattern - the pattern to useParseException - for parsing errorsDateFormatpublic static Date createDate(int s, int m, int h, int dd, int mm, int yy)
s - value of the seconds 1-60m - value of the minutes 1-60h - value of the hours 1-24dd - value of the day 1-31mm - value of the month 1-12yy - value of the year 0-9999public static Date createDate(int dd, int mm, int yy)
dd - value of the day 1-31mm - value of the month 1-12yy - value of the year 0-9999public static Date createDateAfterToday(int ddStep, int mmStep, int yyStep)
ddStep - nb days you want to increase from the current datemmStep - nb months you want to increase from the current dateyyStep - nb years you want to increase from the current datepublic static Date setLastDayOfMonth(Date date)
date - Date to modifypublic static Date setFirstDayOfMonth(Date date)
date - Date to modifypublic static Date setLastDayOfYear(Date date)
date - Date to modifypublic static Date setFirstDayOfYear(Date date)
date - Date to modifypublic static Date setMinTimeOfDay(Date date)
date - to modifypublic static Date setMaxTimeOfDay(Date date)
date - to modifypublic static boolean between(Date myDate, Date beforeDate, Date afterDate)
myDate - the date to testbeforeDate - the first date of the period to testafterDate - the second date of the period to testpublic static boolean currentPeriod(Date beforeDate, Date afterDate)
beforeDate - the first date of the periodafterDate - the second date of the periodbetween(Date, Date, Date)public static int getMonth(Date date)
date - the date to extract monthpublic static int getDifferenceInSeconds(Date beginDate, Date endDate)
beginDate - first dateendDate - second datepublic static int getDifferenceInMinutes(Date beginDate, Date endDate)
beginDate - first dateendDate - second datepublic static int getDifferenceInHours(Date beginDate, Date endDate)
beginDate - first dateendDate - second datepublic static int getDifferenceInDays(Date beginDate, Date endDate)
beginDate - first dateendDate - second datepublic static int getDifferenceInMonths(Date beginDate, Date endDate)
beginDate - first dateendDate - second datepublic static int getAge(Date birthDate)
birthDate - birth datepublic static String getMonthLibelle(int monthNumber, Locale locale)
monthNumber - between 1-12locale - Locale for language supportpublic static String getMonthLibelle(int monthNumber)
monthNumber - between 1-12public static Date getYesterday(Date date)
date - concernedpublic static Calendar getDefaultCalendar(Date date)
date. The default calendar
will be returned (default time zone and locale).date - used to set the calendar timedatepublic static Date truncateToDayOfWeek(Date date)
org.apache.commons.lang3.time.DateUtils#truncate(Date, int)
and giving Calendar.DAY_OF_WEEK argument, but such a call
raise an exception showing that this field is not supported. This method
allows you to bypass this limitation.date - any datepublic static Date getDay(Date date)
date - la date a modifierpublic static Date getEndOfDay(Date date)
date - la date a modifierpublic static Date getDateAndTime(Date day, Date time, boolean useSecond, boolean useMiliSecond)
day et l'heure
donnée dans time.day - le jour à utilisertime - l'heure a utiliseruseSecond - FIXMEuseMiliSecond - FIXMECopyright © 2004–2020 CodeLutin. All rights reserved.