Class Dates
- Author:
- Javier Paniza, Peter Smith
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Dates.DateDistanceaddDateDistances(Dates.DateDistance dis1, Dates.DateDistance dis2) static voidAdd the days to the date.static DatecloneWith2359(Date date) Returns a clone but with 23:59:59:999 for hours, minutes, seconds and milliseconds.static TimestampcloneWith59999(Timestamp date) Returns a clone but with 59 seconds and 999 milliseconds.static TimestampcloneWith999(Timestamp date) Returns a clone but with 999 for milliseconds.static DatecloneWithoutTime(Date date) Returns a clone but without hours, minutes, seconds and milliseconds.static Datecreate(int day, int month, int year) With hour to 0.static Datecreate(int day, int month, int year, int hourofday, int minute, int second) If day, month and year are 0 return null.static DateCurrent date without time.static Dates.DateDistancedateDistance(Date f1, Date f2) Difference of 2 dates in years, months and days.static Dates.DateDistancedateDistance(Date f1, Date f2, boolean includeStartDate) Difference of 2 dates in years, months and days.static Stringstatic StringdateFormatForJSCalendar(boolean includeTime) static Stringstatic intdaysInterval(Date startDate, Date endDate, boolean includeStartDate) Returns number of days between startDate and endDatestatic DatefirstOfMonth(Date date) The date of the first day of month.static DateFormatDateFormat for date + time consistently among all Java versions, according current locale.static DateFormatgetDateTimeFormat(Locale locale) DateFormat for date + time consistently among all Java versions.static DateFormatgetDateTimeFormatForParsing(Locale locale) DateFormat for date + time consistently among all Java versions for using in parsing.static intReturns the day of date.static DateTimeFormatterDateFormat for date + time consistently among all Java versions, according current locale.static DateTimeFormatterDateFormat for date + time consistently among all Java versions, according current locale.static StringgetLocalizedDatePattern(Locale locale) Date partern for short format to be use for both Date and LocalDate.static intReturns the month (1 to 12) of date.static intReturns the year (4 digits) of date.static booleanhasLocalDate(List<MetaProperty> listProperty) Used to verify if the entity has datesstatic booleanIf the hours, minutes, seconds and milliseconds are zero.static booleanisDifferentDay(Date f1, Date f2) Compares if 2 dates are equals at day, month and year level, ignoring time in comparing.static DatelastOfMonth(Date date) The date of the last day of month.static DatelastOfYear(Date date) The date of the last day of year.static DateremoveTime(Date date) Puts hours, minutes, seconds and milliseconds to zero.static voidPut the day to the date.static voidPut the month (1 to 12) to the date.static voidPut the year to the date.static Dates.DateDistancestatic Stringstatic DateCreates a java.sql.Date from a java.util.Date.static StringString with date in short format according current locale.static DateCreates a date with day, month and year of original, but with current time.
-
Constructor Details
-
Dates
public Dates()
-
-
Method Details
-
create
With hour to 0. If day, month and year are 0 return null.The time zone is the default one, so if you print this date in the same JVM you will get the correct one. However, if you move the date object from one machine to other, or save it in a database that will be read from another locale maybe the dates will not match.
-
create
If day, month and year are 0 return null.The time zone is the default one, so if you print this date in the same JVM you will get the correct one. However, if you move the date object from one machine to other, or save it in a database that will be read from another locale maybe the dates will not match.
-
createCurrent
Current date without time. -
getDay
Returns the day of date.If date is null return 0.
-
getYear
Returns the year (4 digits) of date.If date is null returns 0. -
getMonth
Returns the month (1 to 12) of date.If date is null returns 0.
-
setDay
Put the day to the date.If date is null it has no effect (but no exception is thrown)
-
setMonth
Put the month (1 to 12) to the date.If date is null it has no effect (but no exception is thrown)
-
setYear
Put the year to the date.If date is null it has no effect (but no exception is thrown)
-
removeTime
Puts hours, minutes, seconds and milliseconds to zero.- Returns:
- The same date sent as argument (a new date is not created). If null if sent a null is returned.
-
hasTime
If the hours, minutes, seconds and milliseconds are zero.- Returns:
- If argument is null it return false, without throwing exception.
- Since:
- 4.8.1
-
cloneWithoutTime
Returns a clone but without hours, minutes, seconds and milliseconds.- Returns:
- If null if sent a null is returned.
-
cloneWith2359
Returns a clone but with 23:59:59:999 for hours, minutes, seconds and milliseconds.- Returns:
- The same date sent as argument (a new date is not created). If null if sent a null is returned.
-
cloneWith999
Returns a clone but with 999 for milliseconds.- Returns:
- The same date sent as argument (a new date is not created). If null if sent a null is returned.
- Since:
- 7.1.5
-
cloneWith59999
Returns a clone but with 59 seconds and 999 milliseconds.- Returns:
- The same date sent as argument (a new date is not created). If null if sent a null is returned.
- Since:
- 7.1.6
-
toSQL
Creates a java.sql.Date from a java.util.Date.- Parameters:
date- If null returns null
-
toString
String with date in short format according current locale.Current locale is from
Locales.getCurrent().- Parameters:
date- If null returns empty string- Returns:
- Not null
-
getLocalDateTimeFormat
DateFormat for date + time consistently among all Java versions, according current locale.The date format is consistent among all Java versions. While standard Java format differently since Java 9. Current locale is from
Locales.getCurrent().- Returns:
- Not null
- Since:
- 7.4
-
getLocalDateTimeFormatForParsing
DateFormat for date + time consistently among all Java versions, according current locale.The date format is consistent among all Java versions. While standard Java format differently since Java 9. Current locale is from
Locales.getCurrent().- Returns:
- Not null
- Since:
- 7.4
-
getDateTimeFormat
DateFormat for date + time consistently among all Java versions, according current locale.The date format is consistent among all Java versions, including Java 6, 7, 8, 9, 10 and 11. While standard Java format differently since Java 9. Current locale is from
Locales.getCurrent().- Returns:
- Not null
- Since:
- 6.0
-
getDateTimeFormat
DateFormat for date + time consistently among all Java versions.The date format is consistent among all Java versions, including Java 6, 7, 8, 9, 10 and 11. While standard Java format differently since Java 9. Also uses always 4 digits for year no matter the locale (new in v6.5.2).
- Returns:
- Not null
- Since:
- 6.0
-
getDateTimeFormatForParsing
DateFormat for date + time consistently among all Java versions for using in parsing.The date format is consistent among all Java versions, including Java 6, 7, 8, 9, 10 and 11. While standard Java format differently since Java 9. It uses 2 or 4 digits for year depending on locale.
- Returns:
- Not null
- Since:
- 6.5.2
-
getLocalizedDatePattern
Date partern for short format to be use for both Date and LocalDate.It uses always 4 digits for year.
-
withTime
Creates a date with day, month and year of original, but with current time.- Parameters:
date- It is not changed- Returns:
- If arguments is null then is null
-
isDifferentDay
Compares if 2 dates are equals at day, month and year level, ignoring time in comparing.- Parameters:
f1- Can be nullf2- Can be null
-
dateDistance
Difference of 2 dates in years, months and days.- Parameters:
f1- If null returns nullf2- If null returns null
-
dateDistance
Difference of 2 dates in years, months and days.- Parameters:
f1- If null returns nullf2- If null returns null
-
addDateDistances
-
subtractDateDistances
public static Dates.DateDistance subtractDateDistances(Dates.DateDistance dis1, Dates.DateDistance dis2) -
dateFormatForJSCalendar
- Parameters:
locale- Removed in 6.5- Since:
- 4.8.1
-
dateFormatForJSCalendar
- Parameters:
locale- Removed in 6.5
-
timeFormatForJSCalendar
-
dateTimeFormatForJSCalendar
- Parameters:
locale- Removed in 6.5
-
daysInterval
Returns number of days between startDate and endDate- Parameters:
java- .util.Date startDatejava- .util.Date endDateboolean- includeStartDate
-
addDays
Add the days to the date.If date is null it has no effect (but no exception is thrown)
- Since:
- 4.8.1
-
lastOfYear
The date of the last day of year.- Parameters:
The- root date, it is not modified.- Returns:
- If null if sent a null is returned.
- Since:
- 4.8.1
-
lastOfMonth
The date of the last day of month.- Parameters:
The- root date, it is not modified.- Returns:
- If null if sent a null is returned.
- Since:
- 4.8.1
-
firstOfMonth
The date of the first day of month.- Parameters:
The- root date, it is not modified.- Returns:
- If null if sent a null is returned.
- Since:
- 4.8.1
-
hasLocalDate
Used to verify if the entity has dates- Since:
- 7.1
-