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 void main(String... args) {
    Calendar calendar = GregorianCalendar.getInstance();
    calendar.set(YEAR, 2015);/*w w w .java2 s.c om*/
    calendar.set(MONTH, MARCH);
    calendar.set(DAY_OF_MONTH, 1);
    System.out.println(calendar.getTime());
    calendar.add(DAY_OF_MONTH, -1);
    System.out.println(calendar.getTime());

}

From source file:Main.java

public static void main(String[] args) {
    int dayOfWeek = Calendar.SUNDAY;
    Calendar cal = new GregorianCalendar();
    cal.set(2015, 0, 1, 0, 0);//from   w ww . j a  va  2s  .c om
    cal.set(Calendar.DAY_OF_WEEK, dayOfWeek);
    while (cal.get(Calendar.YEAR) == 2015) {
        System.out.println(cal.getTime());
        cal.add(Calendar.DAY_OF_MONTH, 7);
    }
}

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();

    System.out.println("Current week of month is : " + now.get(Calendar.WEEK_OF_MONTH));
    System.out.println("Current week of year is : " + now.get(Calendar.WEEK_OF_YEAR));

    now.add(Calendar.WEEK_OF_MONTH, 1);

    System.out.println("date after one year : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE)
            + "-" + now.get(Calendar.YEAR));
}

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-"
            + now.get(Calendar.YEAR));

    now = Calendar.getInstance();
    now.add(Calendar.MONTH, -5);
    System.out.println("date before 5 months : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE)
            + "-" + now.get(Calendar.YEAR));
}

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-"
            + now.get(Calendar.YEAR));

    now = Calendar.getInstance();
    now.add(Calendar.YEAR, -100);
    System.out.println("date before 100 years : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE)
            + "-" + now.get(Calendar.YEAR));
}

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    System.out.println("Current time : " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":"
            + now.get(Calendar.SECOND));

    now = Calendar.getInstance();
    now.add(Calendar.MINUTE, -50);
    System.out.println("Time before 50 minutes : " + now.get(Calendar.HOUR_OF_DAY) + ":"
            + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND));
}

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-"
            + now.get(Calendar.YEAR));

    now = Calendar.getInstance();
    now.add(Calendar.DATE, -10);
    System.out.println("date before 10 days : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE)
            + "-" + now.get(Calendar.YEAR));
}

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    System.out.println("Current time : " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":"
            + now.get(Calendar.SECOND));

    now = Calendar.getInstance();
    now.add(Calendar.SECOND, -50);
    System.out.println("Time before 50 minutes : " + now.get(Calendar.HOUR_OF_DAY) + ":"
            + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND));
}

From source file:co.com.runt.runistac.logica.TareasLogica.java

public static void main(String[] args) {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DAY_OF_YEAR, 30);
    System.out.println(c);//from  w ww.j a va  2 s .  c o  m
}

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-"
            + now.get(Calendar.YEAR));

    // add days to current date using Calendar.add method
    now.add(Calendar.DATE, 1);

    System.out.println("date after one day : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE)
            + "-" + now.get(Calendar.YEAR));
}