Java Utililty Methods Date Before

List of utility methods to do Date Before

Description

The list of methods to do Date Before are organized into topic(s).

Method

DategetDateBeforeOrAfterV2(int idx)
get Date Before Or After V
return getDateBeforeOrAfter(getFormatDateToDate(getCurrDate()), idx);
longgetDateBeforeSomeMinutes(int minute, long timestamp)
get Date Before Some Minutes
Calendar c = Calendar.getInstance();
c.setTimeInMillis(timestamp);
c.add(Calendar.MINUTE, minute);
return c.getTimeInMillis();
StringgetDateBeforeTheDay(String day, int num)
get Date Before The Day
long longtimes = convertStrToDate(day).getTime() - num * MILLISECOND_IN_DAY;
Date date = new Date(longtimes);
return convertDateToStr(date, YYYYMMDD);
StringgetDateBeforeToday(int num)
get Date Before Today
long longtimes = System.currentTimeMillis() - num * MILLISECOND_IN_DAY;
Date date = new Date(longtimes);
return convertDateToStr(date, "yyyy-MM-dd");
DategetDateBeforTwelveMonth()
get Date Befor Twelve Month
String date = "";
Calendar cla = Calendar.getInstance();
cla.setTime(getCurrentDate());
int year = cla.get(Calendar.YEAR) - 1;
int month = cla.get(Calendar.MONTH) + 1;
if (month > 9) {
    date = String.valueOf(year) + C_DATE_DIVISION + String.valueOf(month) + C_DATE_DIVISION + "01";
} else {
...
DategetDateTimeAfterOfBeforeHour(Integer AfterOfBeforeHour)
get Date Time After Of Before Hour
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.HOUR_OF_DAY, AfterOfBeforeHour);
return calendar.getTime();
DategetDayBeforeOrAfter2(Date time, int days)
get Day Before Or After
Calendar calendar = Calendar.getInstance();
calendar.setTime(time);
calendar.add(Calendar.DAY_OF_MONTH, days);
return calendar.getTime();
longgetDayFormSomeDay(Date date, int n, boolean before)
get Day Form Some Day
Calendar cal = new GregorianCalendar();
cal.setTime(date);
if (before) {
    cal.add(Calendar.DATE, -n);
} else {
    cal.add(Calendar.DATE, n);
return cal.getTime().getTime();
...
intgetDistanceMonthOfTwoDate(Date before, Date after)
get Distance Month Of Two Date
if (before.compareTo(after) >= 0) {
    return 0;
Calendar calendar1 = Calendar.getInstance();
Calendar calendar2 = Calendar.getInstance();
calendar1.setTime(before);
calendar2.setTime(after);
int distance = (calendar2.get(Calendar.YEAR) - calendar1.get(Calendar.YEAR)) * 12
...
DategetMinuteBefore(Date date, int minute)
get Minute Before
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MINUTE, -minute);
return calendar.getTime();