List of usage examples for java.util Calendar add
public abstract void add(int field, int amount);
From source file:Main.java
public static long getTomorrowZeroTimeInMillis() { Calendar calendar = getZeroSecondCalendar(); calendar.add(Calendar.DAY_OF_YEAR, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); return calendar.getTimeInMillis(); }
From source file:Main.java
public static Date addMonth(Date date, int months) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from ww w.j a v a2 s. co m*/ calendar.add(Calendar.MONTH, months); return calendar.getTime(); }
From source file:Main.java
public static String getTime(int laterTime) { Calendar calendar = Calendar.getInstance(); if (laterTime != 0) calendar.add(Calendar.HOUR_OF_DAY, 1); return new SimpleDateFormat("hh:mm a").format(calendar.getTime()); }
From source file:Main.java
public static Date addDate(Date date, int days) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from w w w . ja v a 2 s.c o m calendar.add(Calendar.DATE, days); return calendar.getTime(); }
From source file:Main.java
public static String toDate(Date date, int add) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*ww w .j a v a2 s . c o m*/ calendar.add(Calendar.DATE, add); return toDate(calendar.getTime()); }
From source file:Main.java
public static Date getNextDay(Date date) { Calendar day = Calendar.getInstance(); day.setTime(date);//from w w w .j a v a 2 s . co m day.add(Calendar.DAY_OF_MONTH, 1); return day.getTime(); }
From source file:Main.java
public static Date datePlusNDay(Date date, int n) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*www . ja v a 2 s . co m*/ calendar.add(Calendar.DAY_OF_YEAR, n); return calendar.getTime(); }
From source file:Main.java
/** * @param date//from w w w . j a v a 2 s .c om * @return */ public static String formatToYesterdayOrToday(Date date) { Calendar today = Calendar.getInstance(); Calendar yesterday = Calendar.getInstance(); yesterday.add(Calendar.DATE, -1); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); SimpleDateFormat timeFormatter = new SimpleDateFormat("HH:mm"); if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { return "Today, " + timeFormatter.format(date); } else if (calendar.get(Calendar.YEAR) == yesterday.get(Calendar.YEAR) && calendar.get(Calendar.DAY_OF_YEAR) == yesterday.get(Calendar.DAY_OF_YEAR)) { return "Yesterday, " + timeFormatter.format(date); } else { return DateFormat.format("MMM dd, ", date).toString() + timeFormatter.format(date); } }
From source file:models.Activation.java
public static Activation generateActivationCode(User u, int validForDays) { Activation a = new Activation(); a.user = u;/*from ww w .jav a2 s .c om*/ u.activation = a; a.activationCode = RandomStringUtils.randomAlphanumeric(40); Calendar c = Calendar.getInstance(); c.add(Calendar.DATE, validForDays); a.expirationDate = c.getTime(); a.save(); u.save(); return a; }
From source file:Main.java
/** * Returns the previous day of the passed {@link Date} * * @return The date - 24 hours/*from w w w.jav a 2s. c om*/ */ public static Date getYesterday(Date date) { if (date == null) { return getYesterday(new Date()); } Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.DAY_OF_WEEK, -1); return new Date(cal.getTimeInMillis()); }