Soustraire des mois de la date actuelle en utilisant la méthode Calendar.add

Author:


{filelink=5563}


import java.util.Calendar;

public class SoustraireMois
{

  public static void main(String[] args) {
    Calendar maintenant = Calendar.getInstance();
    System.out.println("Date Actuelle: " + maintenant.get(Calendar.DATE) + "-"
        +(maintenant.get(Calendar.MONTH) + 1) + "-" + maintenant.get(Calendar.YEAR));

    maintenant.add(Calendar.MONTH, -5);
    System.out.println("Date avant 5 mois : " +  maintenant.get(Calendar.DATE) + "-"
        +(maintenant.get(Calendar.MONTH) + 1) + "-" + maintenant.get(Calendar.YEAR));
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *