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 String getTomorrow() {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, 1);
    Date date = cal.getTime();/*  www . j av  a2  s  .  com*/
    SimpleDateFormat sf = new SimpleDateFormat(DATE_FORMAT);
    return sf.format(date);
}

From source file:Main.java

private static Date get2MinsAgo() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MINUTE, -2);

    return calendar.getTime();
}

From source file:Main.java

private static Date get8Hours10MinsAgo() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.HOUR, -8);
    calendar.add(Calendar.MINUTE, -10);

    return calendar.getTime();
}

From source file:Main.java

public static String getNowDate(int afterDay) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_MONTH, afterDay);
    return dateFormat.format(calendar.getTime());
}

From source file:Main.java

public static Calendar addDayToDate(Calendar dataInicio, int quantidade) {
    Calendar dataFim = (Calendar) dataInicio.clone();
    dataFim.add(Calendar.DAY_OF_YEAR, quantidade);
    return dataFim;
}

From source file:Main.java

public static String addDay(int day) {
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd", Locale.getDefault());
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, day);
    return dateFormat.format(cal.getTime());

}

From source file:Main.java

public static Calendar tomorrow() {
    Calendar date = new GregorianCalendar();
    date.add(Calendar.DATE, 1);
    date.set(Calendar.HOUR_OF_DAY, 0);
    date.set(Calendar.MINUTE, 0);
    date.set(Calendar.SECOND, 0);
    date.set(Calendar.MILLISECOND, 0);
    return date;/*from ww  w .  j  a  v a2 s  .co m*/
}

From source file:Main.java

/**
 * Determines the Date "date" adjusted by the number of hours passed in.
 * A Negative int will go back a few hours. This always uses the current
 * date/ time as opposed to the getDateAdjustedByDays() method below which
 * uses the passed in Date argument as the base to use.
 * @param hrs Number of hours to adjust by
 * @return Returns a date object/* ww w. j a  v  a 2  s .  c o m*/
 */
public static Date getDateAdjustedByHours(int hrs) {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, hrs);
    return cal.getTime();
}

From source file:Main.java

public static Date changeDate(int days) {
    Calendar calendar = Calendar.getInstance();

    calendar.add(Calendar.DATE, days);

    return calendar.getTime();
}

From source file:Util.java

public static Date getLastMonthLastDate() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MONTH, -1);

    int max = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    calendar.set(Calendar.DAY_OF_MONTH, max);

    return calendar.getTime();
}