Java Calendar add subtract days

Description

Java Calendar add subtract days

import java.util.Calendar;

public class Main {

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

    System.out.println("Current date : " + now.getTime());

    // add days to current date using Calendar.add method
    now.add(Calendar.DATE, 1);/*from   ww  w.  j av  a  2 s. c  o  m*/

    System.out.println(now.getTime());

    // subtract days from current date using Calendar.add method
    now = Calendar.getInstance();
    now.add(Calendar.DATE, -10);

    System.out.println( now.getTime());

  }
}



PreviousNext

Related