Add months to current date using Calendar.add() method in Java



The given task is to add months to a date (object) using the add() method of the Calendar class. For example, if we need to add 5 months to the date: 26-06-2025, the new date would be 26-11-2025.

Calendar.add() method in Java

The calender.add() method in Java is used to add a specified amount of time to any field of the Calendar. Using this method, we can add months, years, days, etc. This method accepts two parameters: the first one is the field we want to add to, and the second one is the amount we want to add. To add months, the field should be MONTH.

Syntax of the add() method

Following is the syntax of the calender.add() method:

add(Calendar.MONTH, amount);

Example: Adding Months to a Date

In the following example, we will create a Calendar object and then add 5 months to the current date using the calendar.add() method.

import java.util.Calendar;
public class Demo {
   public static void main(String[] args) {
      Calendar calendar = Calendar.getInstance();
      System.out.println("Current Date = " + calendar.getTime());
      // Add 5 months to current date
      calendar.add(Calendar.MONTH, 5);
      System.out.println("Updated Date = " + calendar.getTime());
   }
}

Following is the output of the above program -

Current Date = Thu Nov 22 16:30:08 UTC 2018
Updated Date = Mon Apr 22 16:30:08 UTC 2019
Aishwarya Naglot
Aishwarya Naglot

Writing clean code… when the bugs aren’t looking.

Updated on: 2025-07-21T11:31:51+05:30

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements