List of utility methods to do Date Add
Date | add(Date date, long minutes) add if (date == null) { throw new IllegalArgumentException(); return addMinutes(date, minutes); |
Date | add(Date eredeti, int mihez, int mennyit) add if (eredeti == null) { return null; Calendar cal = new GregorianCalendar(); cal.setTime(eredeti); cal.add(mihez, mennyit); return cal.getTime(); |
Date | add(Date when, int amount, int field) Add an offset to a particular day Calendar calendar = GregorianCalendar.getInstance(TimeZone.getTimeZone("UTC")); calendar.setTime(when); calendar.add(field, amount); return calendar.getTime(); |
Date | add(int datePart, int detal, Date date) add Calendar c = Calendar.getInstance(); if (date != null) c.setTime(date); c.add(datePart, detal); return c.getTime(); |
Date | add(int field, int value, Date fromDate) add fromDate = (fromDate == null) ? new Date() : fromDate; Calendar cal = Calendar.getInstance(); cal.setTime(fromDate); cal.add(field, value); return cal.getTime(); |
long | add(long date, int field, int amount) add Calendar cal = GregorianCalendar.getInstance(); cal.setTime(new Date(date)); cal.add(field, amount); return cal.getTime().getTime(); |
Date | add30Minutes(Date date) add Minutes Calendar currentDate = Calendar.getInstance(); currentDate.setTime(date); int hour = currentDate.get(Calendar.HOUR_OF_DAY); int minute = currentDate.get(Calendar.MINUTE); int addHour = (minute + 30) / 60; minute = (minute + 30) % 60; hour = hour + addHour; currentDate.set(Calendar.HOUR_OF_DAY, hour); ... |
java.util.Date | addCertainTime(java.util.Date date, double hours) add Certain Time int s = (int) (hours * 60 * 60); int hour = s / 3600; int min = (s - hour * 3600) / 60; int sec = s - hour * 3600 - min * 60; java.util.Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.HOUR, hour); cal.add(Calendar.MINUTE, min); ... |
String | addDate(Date date, int add) add Date Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.MONTH, add); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); return formatter.format(calendar.getTime()); |
Date | addDate(Date date, int amount, int type) add Date cal.setTime(date); switch (type) { case Calendar.DATE: cal.add(Calendar.DATE, amount); return cal.getTime(); |