Class DateUtil
java.lang.Object
org.nuiton.util.DateUtil
Library for manipulating dates.
Note:
- Since:
- 1.4.1
- Author:
- fdesbois
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanCheck if the first date in argument is included between the two other dates.static DatecreateDate(int dd, int mm, int yy) Create a new date from day, month and year (French version).static DatecreateDate(int s, int m, int h, int dd, int mm, int yy) Create a new date from day, month and year (French version).static DatecreateDateAfterToday(int ddStep, int mmStep, int yyStep) Create a new date after the current date (today) with modification on day, month and year.static booleancurrentPeriod(Date beforeDate, Date afterDate) Check if the current date is between the two dates in argument.static StringformatDate(Date date, String pattern) Format a date using the pattern in argument.static StringformatDate(Date date, String pattern, Locale locale) static intGet the age of a person born on the date in argument.static DategetDateAndTime(Date day, Date time, boolean useSecond, boolean useMiliSecond) Créer la date qui utilise le jour donné dansdayet l'heure donnée danstime.static DateEnleve les données des heures (hour, minute, second, milli = 0).static CalendargetDefaultCalendar(Date date) Get the calendar corresponding to thedate.static intgetDifferenceInDays(Date beginDate, Date endDate) Do the difference between the two dates in argument.static intgetDifferenceInHours(Date beginDate, Date endDate) Do the difference between the two dates in argument.static intgetDifferenceInMinutes(Date beginDate, Date endDate) Do the difference between the two dates in argument.static intgetDifferenceInMonths(Date beginDate, Date endDate) Do the difference between the two dates in argument.static intgetDifferenceInSeconds(Date beginDate, Date endDate) Do the difference between the two dates in argument.static DategetEndOfDay(Date date) Positionne une date sur la fin d'un jourstatic intGet the month value from a date (between 0 and 11).static StringgetMonthLibelle(int monthNumber) Get libelle of the month corresponding to the number given in argument.static StringgetMonthLibelle(int monthNumber, Locale locale) Get libelle of the month corresponding to the number given in argument.static DateCréer la date qui utilise uniquement l'heure donnée dansdayTime.static DategetYesterday(Date date) Get the date before todaystatic DateParse a date using the pattern in argument.static DatesetFirstDayOfMonth(Date date) Set the first day of month to the date in argument.static DatesetFirstDayOfYear(Date date) Set the first day of year to the date in argument.static DatesetLastDayOfMonth(Date date) Set the last day of month to the date in argument.static DatesetLastDayOfYear(Date date) Set the last day of year to the date in argument.static DatesetMaxTimeOfDay(Date date) Set the max time of the day.static DatesetMinTimeOfDay(Date date) Set the min time of the day : 00:00:00.000.static DatetruncateToDayOfWeek(Date date) Truncate a date to its week (to monday).
-
Field Details
-
DEFAULT_PATTERN
- See Also:
-
MONTH_PATTERN
- See Also:
-
-
Constructor Details
-
DateUtil
public DateUtil()
-
-
Method Details
-
formatDate
-
formatDate
-
parseDate
Parse a date using the pattern in argument. The pattern is the same using for DateFormat object.- Parameters:
date- the String to parsepattern- the pattern to use- Returns:
- a Date corresponding to the String argument parsed
- Throws:
ParseException- for parsing errors- See Also:
-
createDate
Create a new date from day, month and year (French version). The month is the real month of the year and not the one which is stored in Calendar object.- Parameters:
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-9999- Returns:
- a new date
-
createDate
Create a new date from day, month and year (French version). The month is the real month of the year and not the one which is stored in Calendar object. Time is set to 00:00:00.000- Parameters:
dd- value of the day 1-31mm- value of the month 1-12yy- value of the year 0-9999- Returns:
- a new date
-
createDateAfterToday
Create a new date after the current date (today) with modification on day, month and year. You can use negative values on arguments to have a date before today.- Parameters:
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 date- Returns:
- a new date from the current date increase by days, months and years.
-
setLastDayOfMonth
-
setFirstDayOfMonth
-
setLastDayOfYear
-
setFirstDayOfYear
-
setMinTimeOfDay
-
setMaxTimeOfDay
-
between
Check if the first date in argument is included between the two other dates. The argument myDate can be equals to beforeDate or afterDate to validate the includes.- Parameters:
myDate- the date to testbeforeDate- the first date of the period to testafterDate- the second date of the period to test- Returns:
- true if myDate is included between beforeDate and afterDate
-
currentPeriod
Check if the current date is between the two dates in argument.- Parameters:
beforeDate- the first date of the periodafterDate- the second date of the period- Returns:
- true if the current date is included between the two dates, false otherwise
- See Also:
-
getMonth
Get the month value from a date (between 0 and 11).- Parameters:
date- the date to extract month- Returns:
- the month value of the date
-
getDifferenceInSeconds
-
getDifferenceInMinutes
-
getDifferenceInHours
-
getDifferenceInDays
Do the difference between the two dates in argument. The result is a number of days between the two dates. Ex : 28/01/2009 and 08/02/2009 return 11.- Parameters:
beginDate- first dateendDate- second date- Returns:
- a number of days between beginDate and endDate
-
getDifferenceInMonths
Do the difference between the two dates in argument. The result is a number of months between the two dates. Ex : 01/01/2009 and 28/02/2009 return 2 months. Warning, if beginDate is inferior to endDate, the result will be 1 minimum- Parameters:
beginDate- first dateendDate- second date- Returns:
- a number of months between beginDate and endDate
-
getAge
Get the age of a person born on the date in argument. The result is a number of years between the birth date and now. Ex : 01/01/2000 returns 11 years (now date is 26/10/2011).- Parameters:
birthDate- birth date- Returns:
- a number of years between birthDate and now
-
getMonthLibelle
-
getMonthLibelle
Get libelle of the month corresponding to the number given in argument.- Parameters:
monthNumber- between 1-12- Returns:
- a String corresponding to the libelle of the month
-
getYesterday
-
getDefaultCalendar
-
truncateToDayOfWeek
Truncate a date to its week (to monday). It's equivalent to a call toDateUtils.truncate(Date, int)and givingCalendar.DAY_OF_WEEKargument, but such a call raise an exception showing that this field is not supported. This method allows you to bypass this limitation.- Parameters:
date- any date- Returns:
- a date in the same week as given date, a monday. All field below (hours, secondes, ms) are zeroed.
-
getDay
-
getEndOfDay
-
getDateAndTime
Créer la date qui utilise le jour donné dansdayet l'heure donnée danstime.- Parameters:
day- le jour à utilisertime- l'heure a utiliseruseSecond- FIXMEuseMiliSecond- FIXME- Returns:
- la date donnée avec l'heure courante
-
getTime
-