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

/**
 * Add the given amount of millis to the given calendar. The changes are reflected in the given
 * calendar./*from ww  w .j  a va2s.  c  o  m*/
 * @param calendar The calendar to add the given amount of millis to.
 * @param millis The amount of millis to be added to the given calendar. Negative values are
 * also allowed, it will just go back in time.
 */
public static void addMillis(Calendar calendar, int millis) {
    calendar.add(Calendar.MILLISECOND, millis);
}

From source file:Main.java

/**
 * Add the given amount of minutes to the given calendar. The changes are reflected in the given
 * calendar.//from  w w w .  j  av a2  s .  co  m
 * @param calendar The calendar to add the given amount of minutes to.
 * @param minutes The amount of minutes to be added to the given calendar. Negative values are
 * also allowed, it will just go back in time.
 */
public static void addMinutes(Calendar calendar, int minutes) {
    calendar.add(Calendar.MINUTE, minutes);
}

From source file:Main.java

public static void addCalendarWeek(Calendar cal, int weeks) {
    cal.add(Calendar.WEEK_OF_MONTH, weeks);
}

From source file:Main.java

public static Date getLastWeekTime() {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DATE, -6);
    return c.getTime();
}

From source file:Main.java

public static Date getNextDate(int days) {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DAY_OF_WEEK, days);
    return c.getTime();
}

From source file:Main.java

public static void addCalendarMonth(Calendar cal, int months) {
    cal.add(Calendar.MONTH, months);
}

From source file:Main.java

private static long currentTime() {
    Calendar time = Calendar.getInstance();
    time.add(Calendar.MILLISECOND, -time.getTimeZone().getOffset(time.getTimeInMillis()));
    return time.getTime().getTime();
}

From source file:Main.java

public static Date getYesterday() {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -1);
    return cal.getTime();
}

From source file:Main.java

public static void addCalendarSecond(Calendar cal, int seconds) {
    cal.add(Calendar.SECOND, seconds);
}

From source file:Main.java

public static String yesterday() {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DATE, -1);
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    return df.format(c.getTime());
}