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 firstDateOfNextMonth(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//  www .  jav  a2s .  co  m
    calendar.add(Calendar.MONTH, 1);
    Date newDate = calendar.getTime();
    return firstDateOfMonth(newDate);
}

From source file:Main.java

public static String getNextDateByYear(String s, int i) {

    SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMdd");
    java.util.Date date = simpledateformat.parse(s, new ParsePosition(0));
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*  ww w . j av  a2  s .  c  o m*/
    calendar.add(Calendar.YEAR, i);
    date = calendar.getTime();
    s = simpledateformat.format(date);
    return s;
}

From source file:Main.java

public static String getFormatDateAdd(Date date, int amount, String format) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(date);/*from   w w  w. j  a  va2  s . co  m*/
    cal.add(GregorianCalendar.DATE, amount);
    return getFormatDateTime(cal.getTime(), format);
}

From source file:Main.java

static Calendar toNextWholeMinute(Calendar d) {
    Calendar c = new GregorianCalendar();
    c.setTime(d.getTime());//from  w w w . j  a  v  a  2s.  co m
    c.add(Calendar.MINUTE, 1);
    c.set(Calendar.SECOND, 0);
    return c;
}

From source file:Main.java

private static void prepareCalendarNoSunday(Calendar calendar) {
    if (calendar.get(Calendar.DAY_OF_WEEK) == calendar.SUNDAY) {
        calendar.add(Calendar.DATE, 1);
    }//from  ww  w. j  av a 2  s. c om
}

From source file:Main.java

static Calendar toNextWholeHour(Calendar d) {
    Calendar c = new GregorianCalendar();
    c.setTime(d.getTime());/*from  www . j  a  v  a2  s .c  o m*/
    c.add(Calendar.HOUR, 1);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    return c;
}

From source file:Main.java

public static boolean CoversFYStart(Calendar one, Calendar two, Calendar fy_start) throws Exception {
    if (one == null || two == null)
        throw new Exception("CoversFYStart: Null dates passed in");
    if (fy_start == null)
        throw new Exception("CoversFYStart: Null FY Start");

    int fy_month = fy_start.get(Calendar.MONTH);
    int fy_day = fy_start.get(Calendar.DAY_OF_MONTH);
    Calendar cal = (Calendar) one.clone();

    while (true) {
        cal.add(Calendar.DATE, 1);
        int month = cal.get(Calendar.MONTH);
        int day = cal.get(Calendar.DAY_OF_MONTH);
        if (month == fy_month && day == fy_day)
            break;
    }/*from   w ww . ja  v a 2  s. c o  m*/

    return cal.before(two);
}

From source file:Main.java

public static void add(Calendar c, int unit, long increment) {
    while (increment > Integer.MAX_VALUE) {
        c.add(unit, Integer.MAX_VALUE);
        increment -= Integer.MAX_VALUE;
    }/*from ww w  . j a  va  2  s . c om*/
    c.add(unit, (int) increment);
}

From source file:Main.java

public static Date getDateMinuteBefore(Date originalDate, int minutes) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(originalDate);/*  w  w  w .  j av  a2 s .  c  o  m*/
    cal.add(Calendar.MINUTE, minutes * -1);
    return cal.getTime();
}

From source file:Main.java

public static Date getDateDayBefore(Date originalDate, int days) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(originalDate);/*from w w  w. j  a v  a2 s.com*/
    cal.add(Calendar.DAY_OF_MONTH, days * -1);
    return cal.getTime();
}