List of utility methods to do Calendar Add
Calendar | add(int field, long time, int val) Useful routine to add given a number of units to specifed part of given time. Calendar c = Calendar.getInstance(); c.setTimeInMillis(time); c.add(field, val); return c; |
Date | addDay(Calendar c, int days) add Day if (c == null) return null; c.add(Calendar.DAY_OF_MONTH, days); return c.getTime(); |
Date | addMonth(Calendar c, int months) add Month if (c == null) return null; c.add(Calendar.MONTH, months); return c.getTime(); |
Calendar | after(Calendar c, long offset) after Calendar calendar = null; if (c != null) { calendar = c; } else { calendar = Calendar.getInstance(); calendar.setTimeInMillis(calendar.getTimeInMillis() - offset); return calendar; ... |
Calendar | afterNDays(Calendar c, int n) after N Days long offset = n * 24 * 60 * 60 * 1000; Calendar calendar = null; if (c != null) { calendar = c; } else { calendar = Calendar.getInstance(); calendar.setTimeInMillis(calendar.getTimeInMillis() + offset); ... |
Date | getDateAdd(Date date, int amount) get Date Add Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(GregorianCalendar.DATE, amount); return cal.getTime(); |
String | getDateByAddFltHour(float flt) get Date By Add Flt Hour int addMinute = (int) (flt * 60); Calendar cal = new GregorianCalendar(); cal.setTime(new Date()); cal.add(GregorianCalendar.MINUTE, addMinute); return getFormatDateTime(cal.getTime(), "yyyy-MM-dd HH:mm:ss"); |
String | getDateByAddHour(String datetime, int minute) get Date By Add Hour String returnTime = null; Calendar cal = new GregorianCalendar(); SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date; try { date = ft.parse(datetime); cal.setTime(date); cal.add(GregorianCalendar.MINUTE, minute); ... |
String | getFormatCurrentAdd(int amount, String format) get Format Current Add Date d = getDateAdd(new Date(), amount); return getFormatDateTime(d, format); |
Calendar | tomorrow(Calendar c) tomorrow long offset = 1 * 24 * 60 * 60 * 1000; Calendar calendar = null; if (c != null) { calendar = c; } else { calendar = Calendar.getInstance(); calendar.setTimeInMillis(calendar.getTimeInMillis() + offset); ... |