Example usage for java.util Calendar add

List of usage examples for java.util Calendar add

Introduction

In this page you can find the example usage for java.util Calendar add.

Prototype

public abstract void add(int field, int amount);

Source Link

Document

Adds or subtracts the specified amount of time to the given calendar field, based on the calendar's rules.

Usage

From source file:com.orig.gls.admin.user.dao.Access.java

private static Date getExpDate(int numberOfDays) {
    Date today = new Date();
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DAY_OF_MONTH, numberOfDays);
    return cal.getTime();
}

From source file:com.hueemulator.lighting.utils.TestUtils.java

public static String getDateSecondsInFuture(int noSeconds) {
    Calendar calendar = Calendar.getInstance(); // gets a calendar using the default time zone and locale.
    calendar.add(Calendar.SECOND, noSeconds);

    return dateFormat.format(calendar.getTime());
}

From source file:com.acmeair.web.LoaderREST.java

private static Date getArrivalTime(Date departureTime, int mileage) {
    double averageSpeed = 600.0; // 600 miles/hours
    double hours = (double) mileage / averageSpeed; // miles / miles/hour =
                                                    // hours
    double partsOfHour = hours % 1.0;
    int minutes = (int) (60.0 * partsOfHour);
    Calendar c = Calendar.getInstance();
    c.setTime(departureTime);/*w  w  w  .j a v  a  2s  .c  o m*/
    c.add(Calendar.HOUR, (int) hours);
    c.add(Calendar.MINUTE, minutes);
    return c.getTime();
}

From source file:CalendarUtilsTest.java

/**
 * This checks that this is a 7 element iterator of Calendar objects
 * that are dates (no time), and exactly 1 day spaced after each other.
 *///from w w  w  .  j a va  2 s . c  om
private static void assertWeekIterator(Iterator it, Calendar start) {
    Calendar end = (Calendar) start.clone();
    end.add(Calendar.DATE, 6);

    assertWeekIterator(it, start, end);
}

From source file:com.esofthead.mycollab.core.utils.DateTimeUtils.java

/**
 * //w  ww  . ja v  a  2s  .c o m
 * @param date
 * @param duration
 *            Example: Date date = subtractOrAddDayDuration(new Date(), -2);
 *            // Result: the last 2 days
 * 
 *            Date date = subtractOrAddDayDuration(new Date(), 2); //
 *            Result: the next 2 days
 * @return
 */
public static Date subtractOrAddDayDuration(Date date, int duration) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    cal.add(Calendar.DAY_OF_MONTH, duration);
    Date dateExpect = cal.getTime();
    return dateExpect;
}

From source file:Main.java

public static String[] getWeekDays() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    String[] weekDays = new String[7];
    for (int i = 0; i < 7; i++) {
        weekDays[i] = WEEK_DAYS_FORMAT.format(calendar.getTime());
        calendar.add(Calendar.DATE, 1);
    }/* ww w . jav a 2 s. c o m*/
    return weekDays;
}

From source file:Main.java

public static int getDayCounts(Date startDate, Date endDate) {
    int days = 0;
    Calendar startCalendar = Calendar.getInstance();
    startCalendar.setTime(startDate);//from www. j  ava  2s.c om
    Calendar endCalendar = Calendar.getInstance();
    endCalendar.setTime(endDate);
    while (startCalendar.before(endCalendar)) {
        days++;
        startCalendar.add(Calendar.DATE, 1);
    }
    return days;
}

From source file:com.iflytek.kcloud.web.utils.BookDateUtil.java

/**
 * getDay:?. <br/>//  w ww . ja v  a2 s  .  c  om
 *
 * @param gap (0,1,-1....)
 * @return
 * @throws ParseException
 * @author zyyang3
 * @since JDK 1.6
 */
public static String getDay(String time, int gap) throws ParseException {
    Calendar cal = Calendar.getInstance();
    Date datetmp = sdf.parse(time);
    cal.setTime(datetmp);
    cal.add(Calendar.DAY_OF_MONTH, gap);
    Date date = cal.getTime();
    String day = DateFormatUtils.format(date, "yyyy-MM-dd");
    return day;
}

From source file:com.ccf.util.ModDateHeaderUtil.java

/**
 * ??//from   w  ww  .ja va  2s .c  om
 * @param response
 */
public static void setLastModifiedHeader(HttpServletResponse response) {
    SimpleDateFormat df = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss");
    Calendar lastModifiedCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    String lastModified = df.format(lastModifiedCal.getTime());

    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    response.setHeader("Date", df.format(cal.getTime()) + " GMT");
    cal.add(Calendar.DAY_OF_MONTH, 1);
    // response.setHeader("Expires",df.format(cal.getTime())+" GMT");
    response.setHeader("Retry-After", df.format(cal.getTime()) + " GMT");
    response.setHeader("Cache-Control", "public");
    //response.setHeader("Last-Modified",lastModified+" GMT");

    response.setDateHeader("Last-Modified", System.currentTimeMillis() - 60 * 60 * 1000);
    // Force clients to revalidate each time
    // See RFC 2616 (HTTP 1.1 spec) secs 14.21, 13.2.1
    response.setDateHeader("Expires", System.currentTimeMillis() + (expiresOffset * 1000));
    // We may also want this (See 13.2.1 and 14.9.4)
    // response.setHeader("Cache-Control","must-revalidate");
}

From source file:Main.java

public static String[] getShortWeekDays() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    String[] weekDays = new String[7];
    for (int i = 0; i < 7; i++) {
        weekDays[i] = SHORT_WEEK_DAYS_FORMAT.format(calendar.getTime());
        calendar.add(Calendar.DATE, 1);
    }// w w w  .  j  ava2 s  .  co  m
    return weekDays;
}