Class DateUtil
java.lang.Object
com.ssgllc.fish.service.util.registered.DateUtil
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic LocalDateaddDaysObjToDate(LocalDate date, Object daysObj) static LocalDateaddDaysToDate(LocalDate date, Integer days) static StringaddDaysToDateStr(String dateStr, Integer days) Deprecated.static Instantstatic InstantaddMinutes(Instant date, long minutes) static ObjectaddMonthsObjToDate(LocalDate date, Object monthsObj) static ObjectaddMonthsToDate(LocalDate date, Integer months) static StringaddMonthsToDateStr(String dateStr, Integer months) Deprecated.static InstantaddSeconds(Instant date, long seconds) static ObjectaddYearsObjToDate(LocalDate date, Object yearsObj) static ObjectaddYearsToDate(LocalDate date, Integer years) static StringaddYearsToDateStr(String dateStr, Integer years) Deprecated.static Booleanstatic BooleanafterDateStr(String dateOneStr, String dateTwoStr, String pattern) static BooleanafterDateStrPatterned(String dateOneStr, String dateTwoStr) Deprecated.static BooleanafterInstant(Instant dateOne, Instant dateTwo) static BooleanafterOrEqualsDate(LocalDate dateOne, LocalDate dateTwo) static BooleanafterOrEqualsDateStr(String dateOneStr, String dateTwoStr, String pattern) static BooleanafterOrEqualsDateStrPatterned(String dateOneStr, String dateTwoStr) Deprecated.static BooleanafterOrEqualsToday(LocalDate date) static Booleanstatic BooleanafterOrEqualsTodayStr(String dateString, String pattern) Deprecated.static BooleanafterOrEqualsTodayStrPatterned(String dateString) Deprecated.static BooleanafterToday(LocalDate date) static BooleanafterTodayInst(Instant date) static BooleanafterTodayStr(String dateString, String pattern) Deprecated.static BooleanafterTodayStrPatterned(String dateString) Deprecated.static BooleanbeforeDate(LocalDate dateOne, LocalDate dateTwo) static BooleanbeforeDateStr(String dateOneStr, String dateTwoStr, String pattern) static BooleanbeforeDateStrPatterned(String dateOneStr, String dateTwoStr) Deprecated.static BooleanbeforeInstant(Instant dateOne, Instant dateTwo) static BooleanbeforeOrEqualsDate(LocalDate dateOne, LocalDate dateTwo) static BooleanbeforeOrEqualsDateStr(String dateOneStr, String dateTwoStr, String pattern) static BooleanbeforeOrEqualsDateStrPatterned(String dateOneStr, String dateTwoStr) Deprecated.static BooleanbeforeOrEqualsToday(LocalDate date) static Booleanstatic BooleanbeforeOrEqualsTodayStr(String dateString, String pattern) Deprecated.static BooleanbeforeOrEqualsTodayStrPatterned(String dateString) Deprecated.static BooleanbeforeToday(LocalDate date) static BooleanbeforeTodayInst(Instant date) static BooleanbeforeTodayStr(String dateString, String pattern) Deprecated.static BooleanbeforeTodayStrPatterned(String dateString) Deprecated.static intcompareDate(Instant dateOne, Instant dateTwo) static BooleancompareDateStr(String dateOneStr, String dateTwoStr, String pattern, String operator) Deprecated.static BooleancompareLocalDate(LocalDate dateOne, LocalDate dateTwo, String operator) static StringconvertFormat(String date, String fromFormat, String toFormat) static StringconvertFormatObject(Object dateObj, String fromFormat, String toFormat) static StringconvertFormatsObject(Object dateObj, String[] fromFormats, String toFormat) static LocalDatecreateDateFromYearMonthDay(Integer year, Integer month, Integer day) createDateRange(Object minValueInput, Object maxValueInput) static IntegerdaysBetween(LocalDate dateOne, LocalDate dateTwo) static LongdaysBetweenObj(Object firstDateObj, Object secondDateObj, boolean includeWeekendDays) static IntegerdaysBetweenStr(String dateOneStr, String dateTwoStr, boolean includeWeekdays) Deprecated.static LongelapsedBetweenTimes(String hhmmss1, String hhmmss2, String units) static Instantstatic DateConverts the given object into aDateobject.static DategetDateFromInstant(Object instantObj) static DategetDateFromJodaDate(Object jodaDate) static DategetDateFromLocalDate(Object localDate) static LocalDategetDateFromString(String date, String format) static LocalDatestatic IntegergetDaysBetween(LocalDate dateOne, LocalDate dateTwo, boolean includeWeekendDays) static InstantgetInstantFromDate(Date date) static InstantgetInstantFromObject(Object object) static InstantgetInstantFromString(String instantStr) static StringgetIsoDateTimeString(Object object) static LocalDategetLocalDate(Object date) static LocalDategetLocalDateFromDate(Object date) static LocalDategetLocalDateFromInstant(Object instantObj) static LocalDategetLocalDateFromJodaDate(Object jodaDate) static LocalDategetLocalDateFromObject(Object date) static StringgetLocalStrFromUtcInstant(Instant utcInstant) static LocalDategetStartDateOfYearByWeeks(int year) static StringgetStringFromDate(Object date, String format) static StringgetStringFromInstant(Instant instant, String pattern) static StringgetStringFromInstantPatterned(Instant instant) static Integerstatic Integerstatic InstantDeprecated.static booleanstatic booleanisStringValidDate(String date, String format) Checks if a given string can be parsed into a date using the specified format.static booleanisStringValidDateStrict(String date, String format) Checks if a given string strictly matches the specified date format, rejecting “smart” adjustments (e.g., non-leap-year February 29).
UsesResolverStyle.STRICTto enforce exact date matching.
Note: the year pattern should beuuuuinstead ofyyyy, becauseyrepresents “year-of-era” and expects an era designator (e.g., AD/BC).static Booleanstatic BooleanisTodayStr(String dateString, String pattern) Deprecated.static BooleanisTodayStrPatterned(String dateString) Deprecated.static LongmonthsBetween(LocalDate dateOne, LocalDate dateTwo) static LongmonthsBetweenObj(Object firstDateObj, Object secondDateObj) static Stringnow()Deprecated.static LocalDaterandomDate(LocalDate from, LocalDate to) static Booleanstatic BooleansameDateStr(String dateOneStr, String dateTwoStr, String pattern) static BooleansameDateStrPatterned(String dateOneStr, String dateTwoStr) Deprecated.voidsetDatabase(String dateFormat) static DatesetTimeToNoon(Date date) static Instantstatic Stringtoday()Deprecated.static LocalDateDeprecated.static IntegerweekdaysBetween(LocalDate dateOne, LocalDate dateTwo) static LongyearsBetween(LocalDate dateOne, LocalDate dateTwo) static LongyearsBetweenObj(Object firstDateObj, Object secondDateObj)
-
Field Details
-
DEFAULT_DATE_PATTERN
-
-
Method Details
-
setDatabase
-
getLocalDateFromJodaDate
-
getLocalDateFromInstant
-
getLocalDateFromDate
-
getDate
Converts the given object into aDateobject. This method attempts to interpret the input object as a valid date representation and convert it into aDate. The supported input types are:Date- Returns the input as is.LocalDate- Converts to aDateusing the system's default timezone.LocalDate- Converts to aDateusing the system's default timezone.Instant- Converts to aDatepreserving the UTC representation.String- Attempts to parse the string into aDate, assuming it is in the default date format or ISO-8601.Long- Treats the long value as an epoch timestamp in milliseconds.
getDate(getLocalDate(string))to handle timezone correctly. -
getDateFromInstant
-
getDateFromLocalDate
-
setTimeToNoon
-
getDateFromJodaDate
-
isDate
-
getLocalDate
-
getLocalDateFromObject
-
getStringFromDate
-
getDateFromStringObject
-
getDateFromString
-
isStringValidDate
Checks if a given string can be parsed into a date using the specified format.- Parameters:
date- The date string to validate.format- The date format pattern.- Returns:
trueif parsing succeeds;falseotherwise.
Groovy example:
return stringUtil.isStringValidDate("2025-07-02", "yyyy-MM-dd")
Returns:
true
SpEL example:
#isStringValidDate("2025-07-02", "yyyy-MM-dd")
Returns:
true
Note: Ifdateisnullor cannot be parsed according toformat, this method returnsfalse.
-
isStringValidDateStrict
Checks if a given string strictly matches the specified date format, rejecting “smart” adjustments (e.g., non-leap-year February 29).
UsesResolverStyle.STRICTto enforce exact date matching.
Note: the year pattern should beuuuuinstead ofyyyy, becauseyrepresents “year-of-era” and expects an era designator (e.g., AD/BC).- Parameters:
date- The date string to validate.format- The date format pattern to enforce.- Returns:
trueif strict parsing succeeds;falseotherwise.
Groovy example:
// Feb 29, 2025 is invalid because 2025 is not a leap year return stringUtil.isStringValidDateStrict('02/29/2025', 'MM/dd/uuuu')
Returns:
false
SpEL example:
#isStringValidDateStrict('02/29/2025', 'MM/dd/uuuu')
Returns:
false
Note: Returnsfalseifdateisnullor does not strictly conform to the given format (including invalid leap-year dates).
-
getStringFromInstant
-
getStringFromInstantPatterned
-
getInstantFromString
-
getLocalStrFromUtcInstant
-
addDaysObjToDate
-
addDaysToDate
-
addMonthsObjToDate
-
addMonthsToDate
-
addYearsObjToDate
-
addYearsToDate
-
daysBetweenObj
-
monthsBetweenObj
-
yearsBetweenObj
-
createDateFromYearMonthDay
-
convertFormatObject
-
convertFormatsObject
-
convertFormat
-
isTodayStrPatterned
Deprecated. -
beforeTodayStrPatterned
Deprecated. -
beforeOrEqualsTodayStrPatterned
Deprecated. -
afterTodayStrPatterned
Deprecated. -
afterOrEqualsTodayStrPatterned
Deprecated. -
compareDate
-
isTodayStr
Deprecated. -
beforeTodayStr
Deprecated. -
beforeOrEqualsTodayStr
Deprecated. -
afterTodayStr
Deprecated. -
afterOrEqualsTodayStr
Deprecated. -
sameDateStrPatterned
Deprecated. -
beforeDateStrPatterned
Deprecated. -
beforeOrEqualsDateStrPatterned
@Deprecated public static Boolean beforeOrEqualsDateStrPatterned(String dateOneStr, String dateTwoStr) Deprecated. -
afterDateStrPatterned
Deprecated. -
afterOrEqualsDateStrPatterned
@Deprecated public static Boolean afterOrEqualsDateStrPatterned(String dateOneStr, String dateTwoStr) Deprecated. -
sameDateStr
-
beforeDateStr
-
beforeOrEqualsDateStr
-
afterDateStr
-
afterOrEqualsDateStr
-
isToday
-
beforeToday
-
beforeOrEqualsToday
-
afterToday
-
afterOrEqualsToday
-
sameDate
-
beforeDate
-
beforeOrEqualsDate
-
afterDate
-
afterOrEqualsDate
-
startOfToday
-
endOfToday
-
beforeTodayInst
-
beforeOrEqualsTodayInst
-
afterTodayInst
-
afterOrEqualsTodayInst
-
beforeInstant
-
afterInstant
-
addHours
-
addMinutes
-
addSeconds
-
compareLocalDate
-
compareDateStr
@Deprecated public static Boolean compareDateStr(String dateOneStr, String dateTwoStr, String pattern, String operator) Deprecated. -
addDaysToDateStr
Deprecated. -
addMonthsToDateStr
Deprecated. -
addYearsToDateStr
Deprecated. -
today
Deprecated. -
todayDate
Deprecated. -
now
Deprecated. -
instantNow
Deprecated. -
daysBetween
-
weekdaysBetween
-
monthsBetween
-
yearsBetween
-
getDaysBetween
-
daysBetweenStr
@Deprecated public static Integer daysBetweenStr(String dateOneStr, String dateTwoStr, boolean includeWeekdays) Deprecated. -
getInstantFromDate
-
getInstantFromObject
-
getIsoDateTimeString
-
elapsedBetweenTimes
-
randomDate
-
getYearOfDateByWeeks
-
getStartDateOfYearByWeeks
-
getWeekOfDateByWeeks
-
createDateRange
-