List of utility methods to do Date Before
Date | getBeforeOrAfterDateByDayNumber(int dayNumber) get Before Or After Date By Day Number return getBeforeOrAfterDateByDayNumber(new Date(), dayNumber); |
Date | getDateBefore(Date d, int day) get Date Before Calendar now = Calendar.getInstance(); now.setTime(d); now.set(Calendar.DATE, now.get(Calendar.DATE) - day); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = simpleDateFormat.parse(simpleDateFormat.format(now.getTime())); return date; |
Date | getDateBefore(Date d, int day) get Date Before Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.HOUR_OF_DAY, 0);
now.set(Calendar.MINUTE, 0);
now.set(Calendar.SECOND, 0);
now.set(Calendar.MILLISECOND, 0);
now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
return now.getTime();
...
|
Date | getDateBefore(Date date, int days) Get date before the input date according to param-days Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(java.util.Calendar.DAY_OF_YEAR, days);
return calendar.getTime();
|
String | getDateBefore(int offsetDay, String strFormat) get Date Before String strDay = ""; long nNow = getTimestamp(); long mydate = nNow - (long) offsetDay * 24 * 3600 * 1000; SimpleDateFormat sdf = new SimpleDateFormat(strFormat); strDay = sdf.format(new Date(mydate)); return strDay; |
Date | getDateBefore(int year, int month, int day) get Date Before Date result = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(result); calendar.add(Calendar.YEAR, year); calendar.add(Calendar.MONTH, month); calendar.add(Calendar.DAY_OF_MONTH, day); result = calendar.getTime(); return result; ... |
String | getDateBefore(String d, int day) get Date Before SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); Calendar now = Calendar.getInstance(); try { now.setTime(format.parse(d)); now.set(Calendar.DATE, now.get(Calendar.DATE) - day); } catch (ParseException e) { e.printStackTrace(); return format.format(now.getTime()); |
Date | getDateBeforeHours(Date date, int hours) get Date Before Hours return getDateAfterHours(date, 0 - hours);
|
Date | getDateBeforeNextMonth(Date date, Integer month, Integer day) get Date Before Next Month if (date == null || month == null || day == null) { return date; Calendar cal = Calendar.getInstance(Locale.CHINA); cal.setTime(date); cal.add(Calendar.MONTH, month); cal.add(Calendar.DATE, day); return cal.getTime(); ... |
Date | getDateBeforeOrAfter(int iDate) get Date Before Or After Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, iDate);
return cal.getTime();
|