Java Data Type How to - Add one month to a Date


We would like to know how to add one month to a Date.


import java.util.GregorianCalendar;
import java.util.Calendar;
//  w  ww .ja  va  2 s  . c  o m
public class Main {
    public static void main(String[] args) {

        Calendar today = new GregorianCalendar();
        Calendar purchased = new GregorianCalendar();

        purchased.add(Calendar.DAY_OF_MONTH, 1);

        Calendar lastActDate = new GregorianCalendar();
        lastActDate.setTimeInMillis(today.getTimeInMillis() - purchased.getTimeInMillis());