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 int getNextMonth(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);/*  www . j a v  a 2 s  .co  m*/
    c.add(Calendar.MONTH, 1);
    return c.get(Calendar.MONTH);
}

From source file:Main.java

public static Date addMouth(Date date, int step) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//from   w w  w  .j a va 2 s .  c  o m
    calendar.add(Calendar.MONTH, step);
    return calendar.getTime();
}

From source file:Main.java

public static Date addYear(Date date, int step) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);// ww w. j av  a  2s  .c  o  m
    calendar.add(Calendar.YEAR, step);
    return calendar.getTime();
}

From source file:Main.java

public static void addCalendarDay(Calendar cal, int days) {
    cal.add(Calendar.DAY_OF_MONTH, days);
}

From source file:Main.java

public static String getTomorrowDate() {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    Date date = new Date(System.currentTimeMillis());

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from   ww w  . java  2 s.  co m*/
    cal.add(Calendar.DAY_OF_YEAR, +1);

    return sdf.format(cal.getTime());
}

From source file:Main.java

public static Date plusHours(Date date, int n) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//from   ww  w  . j a va2  s. c om
    calendar.add(Calendar.HOUR_OF_DAY, n);
    return calendar.getTime();
}

From source file:Main.java

public static String getBeforeTime(int months, SimpleDateFormat format, Date now) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(now);/*from   w w w.  j ava2s .  c om*/
    calendar.add(calendar.MONTH, -months);
    return format.format(calendar.getTime());
}

From source file:Main.java

public static Calendar getDateComparedToCurrent(Calendar current, int daysToAdd) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(current.getTime());//from w w w  .ja  va 2 s  .com
    cal.add(Calendar.DATE, daysToAdd);
    return cal;
}

From source file:Main.java

public static Date add(Date date, int amount, int field) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//w  w w .j a va2 s. co m
    calendar.add(field, amount);
    return calendar.getTime();
}

From source file:Main.java

/**
 * This method adds days to a date//from  w  ww .j a  v a2s  . co  m
 *
 * @param date the date.
 * @param days the number of days to add.
 */
public static Date getDateAfterAddition(Date date, int days) {
    Calendar cal = Calendar.getInstance();

    cal.setTime(date);
    cal.add(Calendar.DATE, days);

    return cal.getTime();
}