Substract 30 days from the calendar in Java

Description

The following code shows how to substract 30 days from the calendar.

Example


/*from   ww  w .  ja v a  2  s . com*/
import java.util.Calendar;

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

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

    // Substract 30 days from the calendar
    cal.add(Calendar.DATE, -30);
    System.out.println("30 days 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