Java Calendar add subtract years

Description

Java Calendar add subtract years

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.YEAR, 10);//from w w w  .  j  a  v  a  2s .  c  o  m

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

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

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

  }
}



PreviousNext

Related