List of usage examples for java.util Calendar add
public abstract void add(int field, int amount);
From source file:net.firejack.platform.core.utils.DateUtils.java
/** * Decrements the date by one week/*from w ww. j av a2 s . co m*/ * @param date - date to be decremented * @return decremented date */ public static Date decDateByWeek(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(Calendar.WEEK_OF_MONTH, -1); date.setTime(cal.getTimeInMillis()); return date; }
From source file:com.appeligo.search.entity.Message.java
public static void deleteOldMessages(int days, int maxAttempts) { Session session = getSession();//from w w w . j a va 2s. co m Query query = session.getNamedQuery("Message.deleteOldMessages"); Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR_OF_DAY, (0 - (days * 24))); query.setTimestamp("oldestSent", new Timestamp(cal.getTimeInMillis())); query.setInteger("maxAttempts", maxAttempts); query.executeUpdate(); }
From source file:Main.java
private static void populateDayRanges(Date start, Date end) { Calendar startCal = Calendar.getInstance(); startCal.setTime(start);/* ww w. ja va 2 s . c o m*/ Calendar endCal = Calendar.getInstance(); endCal.setTime(end); sDayNames.clear(); sDayAbbreviations.clear(); for (Date date = startCal.getTime(); startCal.before(endCal); startCal.add(Calendar.DATE, 1), date = startCal.getTime()) { sDayNames.add(dayLabelFormatter.format(date)); sDayAbbreviations.add(dayAbbrevFormatter.format(date)); } }
From source file:net.firejack.platform.core.utils.DateUtils.java
/** * Converts the number of days since the epoch to the date * @param days - number of days since the epoch * @return date//from w ww. ja v a 2 s .co m */ public static Date epochDays2Date(int days) { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(0); cal.add(Calendar.DAY_OF_YEAR, days); return cal.getTime(); }
From source file:Main.java
public static java.util.Date getDateEnd(java.util.Date d) { Calendar c = Calendar.getInstance(); c.clear();//from www.j av a2 s . co m Calendar co = Calendar.getInstance(); co.setTime(d); c.set(Calendar.DAY_OF_MONTH, co.get(Calendar.DAY_OF_MONTH)); c.set(Calendar.MONTH, co.get(Calendar.MONTH)); c.set(Calendar.YEAR, co.get(Calendar.YEAR)); c.add(Calendar.DAY_OF_MONTH, 1); c.add(Calendar.MILLISECOND, -1); return c.getTime(); }
From source file:com.baomidou.framework.common.util.DateUtil.java
/** * /* w ww . j av a 2s .c o m*/ * ???? * * @param date * * * @param calendarField * ??????Calendar * * @param offsite * ??????????? * * @return ??? * */ public static Date getOffsiteDate(Date date, int calendarField, int offsite) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(calendarField, offsite); return cal.getTime(); }
From source file:Main.java
/** * Add date time with nine minutes./*from ww w . j a v a2 s . c o m*/ * * @param listing the listing * @param currentTime the current time * @param isPast true/false if past time */ private static void addDateTimeWithNineMinutes(final List<Long> listing, final long currentTime, final boolean isPast) { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currentTime); calendar.add(Calendar.MINUTE, isPast ? -9 : 9); listing.add(calendar.getTimeInMillis()); }
From source file:Main.java
/** * Add date time with fifty one minutes. * * @param listing the listing/*from w w w. j a v a 2 s . c o m*/ * @param currentTime the current time * @param isPast true/false if past time */ private static void addDateTimeWithFiftyOneMinutes(final List<Long> listing, final long currentTime, final boolean isPast) { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currentTime); calendar.add(Calendar.MINUTE, isPast ? -51 : 51); listing.add(calendar.getTimeInMillis()); }
From source file:Main.java
/** * Add date time with five hours./*w w w.ja v a 2s. c om*/ * * @param listing the listing * @param currentTime the current time * @param isPast true/false if past time */ private static void addDateTimeWithFiveHours(final List<Long> listing, final long currentTime, final boolean isPast) { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currentTime); calendar.add(Calendar.HOUR, isPast ? -3 : 3); listing.add(calendar.getTimeInMillis()); }
From source file:Main.java
/** * Add date time with six months.//from w ww . j av a 2s . c om * * @param listing the listing * @param currentTime the current time * @param isPast true/false if past time */ private static void addDateTimeWithSixMonths(final List<Long> listing, final long currentTime, final boolean isPast) { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currentTime); calendar.add(Calendar.MONTH, isPast ? -6 : 6); listing.add(calendar.getTimeInMillis()); }