custom manipulations with dates. (e.g. to get a number of days between dates or to get last day of month, etc)
Type Params | Return Type | Name and description |
---|---|---|
|
static Date |
addMonths(Date date, int number) Add the specified number of months to given date. |
|
static Date |
convertStringToDateTime(String strDt, String format) Converts a date to a specified format. |
|
static Date |
fromLocalDate(LocalDate localDate, ZoneId zoneId = ZoneId.systemDefault() |
|
static Date |
fromLocalDateTime(LocalDateTime localDate, ZoneId zoneId = ZoneId.systemDefault() |
|
static Calendar |
getCalendarInstanceByDate(Date date) Returns a Calendar instance for a given date. |
|
static Calendar |
getCurrentCalendarInstance() Returns a Calendar instance for a given date. |
|
static long |
getDateDifference_inHours(Date date) Calculates a number of hours between now and the specified date. |
|
static int |
getDaysBetween(Date start, Date end) Returns the number of days between two dates. |
|
static Date |
getFirstDateOfMonth() Returns the first day of the current month and sets time to midnight. |
|
static Date |
getFirstDayOfMonth(Date date, int addMonth = 0) |
|
static Date |
getFirstDayOfWeek() Returns the first day of the current week and sets time to midnight. |
|
static Date |
getFourMonthsBack() |
|
static Date |
getLastDayOfMonth(Date date, int addMonth = 0) |
|
static Date |
getLastDayOfWeek() Returns the last day of the current week and sets time to before midnight (23:59:59). |
|
static Date |
getLastWeekEndDate() |
|
static int |
getLastWeekStartDate() |
|
static int |
getMonthDiff(Date one, Date two) Get Month difference between two dates |
|
static String |
getMonthLetter(String periodToPost) Returns the first letter of a month. |
|
static String |
getMonthLetterByNum(int monthNumber) Returns the first letter(uppercase) of a specified month. |
|
static Date |
getNextMonth() Returns the next month for current date and sets the day number to 1. |
|
static Date |
getPreviousMonth() Returns the previous month for current date and sets the day number to 1. |
|
static Date |
getThreeMonthsBack() |
|
static Date |
getTwoMonthsBack() |
|
static int |
getYearOf(Date date) Returns the year of the date specified. |
|
static int |
getYearOf(TemporalAccessor date) Returns the year of the date specified. |
|
static boolean |
isTodayTheDate(String period, int dayNumber) Checks if the current day number is equal to specified day number in a given period. |
|
static Calendar |
setTime(Calendar cal, int hours = 0, int minutes = 0, int seconds = 0, int milliseconds = 0) Sets time for a given calendar instance. |
|
static Calendar |
setTimeAsOfMidnight(Calendar cal) Sets time to midnight(00:00:00) for a given date instance. |
|
static Calendar |
setTimeBeforeMidnight(Calendar cal) Sets time to 23:59:59 for a given calendar instance. |
|
static Date |
setToMidnight(Date date) Sets time to midnight(00:00:00) for a given date instance. |
|
static Date |
shiftCurrentDateByMonths(int months) Shifts the current date by specified number of months and sets current day of month to 1. |
|
static LocalDate |
toLocalDate(Date date, ZoneId zoneId = ZoneId.systemDefault() |
|
static LocalDateTime |
toLocalDateTime(Date date, ZoneId zoneId = ZoneId.systemDefault() |
Add the specified number of months to given date.
date
- The datenumber
- number of months to addConverts a date to a specified format.
strDt
- a date as a stringformat
- a formatReturns a Calendar instance for a given date.
date
- a dateReturns a Calendar instance for a given date.
date
- a dateCalculates a number of hours between now and the specified date.
date
- a date for which to calculate the differenceReturns the number of days between two dates. start == end : 0 start is 10 days after end : 10 start is 10 days before end: -10
Returns the first day of the current month and sets time to midnight.
Returns the first day of the current week and sets time to midnight.
Returns the last day of the current week and sets time to before midnight (23:59:59).
Get Month difference between two dates Returns int one.month = two.month : 0 one.month = (two.month - 1) : 1 one.month = (two.month + 1) : -1
Returns the first letter of a month. expected format: YYYYMM
periodToPost
- a string which contains date in format YYYYMMReturns the first letter(uppercase) of a specified month.
monthNumber
- number of a monthReturns the next month for current date and sets the day number to 1.
Returns the previous month for current date and sets the day number to 1.
Returns the year of the date specified.
Returns the year of the date specified.
Checks if the current day number is equal to specified day number in a given period.
Sets time for a given calendar instance.
cal
- a calendar instancehours
- hours, by default is 0minutes
- minutes, by default is 0seconds
- seconds, by default is 0milliseconds
- milliseconds, by default is 0Sets time to midnight(00:00:00) for a given date instance.
date
- a date for which to setup timeSets time to 23:59:59 for a given calendar instance.
date
- a calendar for which to setup timeSets time to midnight(00:00:00) for a given date instance.
date
- a date for which to setup timeShifts the current date by specified number of months and sets current day of month to 1.
months
- number of months to shift