Calendar add() Method in Java with Examples Last Updated : 02 Nov, 2021 Comments Improve Suggest changes Like Article Like Report The add() method of Calendar class present inside is used to add or subtract from the given calendar field(int field), a specific amount of time(int amt), based on the calendar's rules. Syntax: public abstract void add(int field, int amt) Parameters: The method takes two parameters: The field of the calendar on which the operation is to be performed. (Integer type)The amount of time needed to be subtracted. (Integer type) Return Value: The method does not return any value. Example 1: Java // Java Program to Illustrate add() Method // of Calendar class // Importing required classes import java.util.Calendar; // Main class public class CalendarClassDemo { // Main driver method public static void main(String args[]) { // Creating a Calendar class object Calendar calndr = Calendar.getInstance(); // Displaying the current date // using getTime() method System.out.println("Current Date: " + calndr.getTime()); // Adding 50 days to the // Current Calendar // using add() method calndr.add(Calendar.DATE, 50); // Displaying the date now using getTime() method System.out.println("After 50 days: " + calndr.getTime()); // Subtracting 6 months from // the Current calendar calndr.add(Calendar.MONTH, -6); // Displaying the date now using getTime() method System.out.println("6 months ago it was: " + calndr.getTime()); // Subtracting 2 year from // the Current calendar calndr.add(Calendar.YEAR, -2); // Displaying the date now using getTime() method System.out.println("2 years ago it was: " + calndr.getTime()); } } Output: Current Date: Tue Feb 12 10:54:21 UTC 2019 After 50 days: Wed Apr 03 10:54:21 UTC 2019 6 months ago it was: Wed Oct 03 10:54:21 UTC 2018 2 years ago it was: Mon Oct 03 10:54:21 UTC 2016 Example 2: Java // Java Program to Illustrate add() Method // of Calendar class // Importing required classes import java.util.Calendar; // Main class public class GFG { // Main driver method public static void main(String args[]) { // Creating a calendar object Calendar calndr = Calendar.getInstance(); // Displaying the current date // using getTime() method System.out.println("Current Date: " + calndr.getTime()); // Adding 30 days to the current calendar // using add() method calndr.add(Calendar.DATE, 30); // Printing the corresponding date System.out.println("After 30 days: " + calndr.getTime()); // Subtracting 3 months from the current calendar calndr.add(Calendar.MONTH, -3); // Printing the corresponding date System.out.println("3 months ago it was: " + calndr.getTime()); // Subtracting 10 years from // the Current calendar calndr.add(Calendar.YEAR, -10); // Printing the corresponding date System.out.println("10 years ago it was: " + calndr.getTime()); } } Output: Current Date: Tue Feb 12 10:54:24 UTC 2019 After 30 days: Thu Mar 14 10:54:24 UTC 2019 3 months ago it was: Fri Dec 14 10:54:24 UTC 2018 10 years ago it was: Sun Dec 14 10:54:24 UTC 2008 Comment More infoAdvertise with us Next Article Calendar add() Method in Java with Examples chinmoy lenka Follow Improve Article Tags : Misc Java Java - util package Java-Functions Java-Calendar +1 More Practice Tags : JavaMisc Similar Reads Calendar get() method in Java with Examples The get(int field_value) method of Calendar class is used to return the value of the given calendar field in the parameter. Syntax: public int get(int field) Parameters: The method takes one parameter field_value of integer type and refers to the calendar whose value is needed to be returned. Return 2 min read Calendar set() Method in Java with Examples The set(int calndr_field, int new_val) method in Calendar class is used to set the calndr_field value to a new_val. The older field of this calendar get replaced by a new field. Syntax: public void set(int calndr_field, int new_val) Parameters: The method takes two parameters: calndr_field: This is 2 min read Calendar clear() Method in Java with Examples The clear() method in Calendar class is used to set all the calendar field values and the time value of this Calendar undefined. Note: Implementation of calendar class may use default field values for date and time calculations. Syntax: public final void clear() Parameters: The method does not take 2 min read Calendar isSet() Method in Java with Examples The isSet(int calndr_field) method in Calendar class is used to check whether the given calendar field has a value set or not. All the Cases for which the values have been set by the calculations of the internal field are triggered by a get method call. Syntax: public final boolean isSet(int calndr_ 2 min read Calendar clone() Method in Java with Examples The clear() method in Calendar class is used to clone a calendar object. It basically creates a shallow copy of this object. Syntax: public Object clone() Parameters: The method does not take any parameters. Return Value: The method does not return any value. Below programs illustrate the working of 2 min read Calendar setTime() Method in Java with Examples The setTime(Date dt) method in Calendar class is used to set Calendars time represented by this Calendar's time value, with the given or passed date as a parameter. Syntax: public final void setTime(Date dt)) Parameters: The method takes one parameter dt of Date type and refers to the given date tha 2 min read Calendar complete() Method in Java with Examples The complete() method in Calendar class is used to fill any unset fields of the calendar fields. It follows the following process of completion: At first, if the time value has not been calculated, the computeTime() method is called to calculate it from calendar field values. Second, to calculate al 2 min read Calendar toString() Method in Java with Examples The toString() method in Calendar class is used to get the string representation of the Calendar object. This method in Calendar Class is just for debug process and not to be used as an operation. Syntax: public String toString() Parameters: The method does not take any parameters. Return Value: The 1 min read Calendar hashCode() Method in Java with Examples The hashCode() method in Calendar class is used to return the hash code for this Calendar Object.Syntax: public int hashCode() Parameters: The method does not take any parameters.Return Value: The method returns the hash code value for this calendar object..Below programs illustrate the working of h 2 min read Date clone() method in Java with Examples The clone() method of Date class in Java returns the duplicate of the passed Date object. This duplicate is just a shallow copy of the given Date object.Syntax: public Object clone() Parameters: The method does not accept any parameters.Return Value: The method returns a clone of the object.Below pr 2 min read Like