Java Calendar add subtract months

Description

Java Calendar add subtract months

import java.util.Calendar;

public class Main {

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

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

    now.add(Calendar.MONTH, 10);//from w  w  w.ja  v  a 2s. c  om

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

    now = Calendar.getInstance();
    now.add(Calendar.MONTH, -10);

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

  }
}



PreviousNext

Related