Substract 1 year from the calendar in Java

Description

The following code shows how to substract 1 year from the calendar.

Example


//from   w  w  w . j a  v a 2s  .  co m
import java.util.Calendar;

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

    System.out.println("Today : " + cal.getTime());

    // Substract 1 year from the calendar
    cal.add(Calendar.YEAR, -1);
    System.out.println("1 year ago: " + cal.getTime());
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Date »




Date Get
Date Set
Date Format
Date Compare
Date Convert
Date Calculation
Date Parse
Timezone