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:Main.java

public static Date dateAddDays(Date date, int days) {

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from w ww.  j av  a 2  s .  c  o  m
    cal.add(Calendar.DAY_OF_YEAR, days);
    return cal.getTime();
}

From source file:Main.java

public static Date addDays(Date date, int days) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//  ww  w .  j  av a2  s. c om
    cal.add(Calendar.DAY_OF_MONTH, days);
    return cal.getTime();
}

From source file:Main.java

public static Date addDay(Date date, int n) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*  w w w.j  av a 2 s .  c  om*/
    cal.add(Calendar.DATE, n);
    return cal.getTime();

}

From source file:Main.java

public static Date addTimeInterval(Date origin, int value, int unit) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(origin);//from   w  w w  . j  a  v  a  2  s.co  m
    cal.add(unit, value);
    return cal.getTime();
}

From source file:Main.java

public static Date addMonth(Date date, int n) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//w  w  w.  jav  a  2s .  c o  m
    cal.add(Calendar.MONTH, n);
    return cal.getTime();

}

From source file:Main.java

public static Date offsiteDate(Date date, int calendarField, int offsite) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from  w w w  .ja  va2 s . co  m
    cal.add(calendarField, offsite);
    return cal.getTime();
}

From source file:Main.java

/**
 * Checks for the given calendar is in coming 7 days
 * @param calendar/*from   w  w  w  .  j  a va  2 s.  c  o  m*/
 * @return true if given calendar is in coming week
 */
public static boolean isComingWeek(Calendar calendar) {
    boolean flag = false;
    Calendar calendar2 = Calendar.getInstance();
    calendar2.add(Calendar.DATE, 7);
    if (calendar.before(calendar2)) {
        flag = true;
    }
    return flag;
}

From source file:Main.java

private static long countDays(Calendar start, Calendar end) {
    long totalNumberOfDays = 0;
    while (start.before(end)) {
        start.add(Calendar.DAY_OF_MONTH, 1);
        totalNumberOfDays++;/*from w w w  .  j  a  v a  2  s.c o m*/
    }
    return totalNumberOfDays;
}

From source file:Main.java

public static int getDayNum(int index) {
    java.util.Calendar calendar = new java.util.GregorianCalendar();

    calendar.add(Calendar.DATE, index);//
    int dWeek = calendar.get(Calendar.DAY_OF_WEEK);
    int realDay = (dWeek - 1) == 0 ? 7 : (dWeek - 1);

    return realDay;
}

From source file:Main.java

public static Long getIncTimeInMillis(Date originDate, int increment) {
    if (null == originDate)
        return null;
    Calendar c = Calendar.getInstance();
    c.setTime(originDate);/*  www . j a v  a  2s  .com*/
    c.add(Calendar.MINUTE, increment);
    return c.getTimeInMillis();
}