- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Increment a Month using the Calendar Class in Java
Import the following package for Calendar class in Java
import java.util.Calendar;
Firstly, create a Calendar object and display the current date
Calendar calendar = Calendar.getInstance(); System.out.println("Current Date = " + calendar.getTime());
Now, let us increment the month using the add() method and Calendar.MONTH constant −
calendar.add(Calendar.MONTH, 2);
The following is an example
Example
import java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println("Current Date = " + calendar.getTime()); // Incrementing Month by 2 calendar.add(Calendar.MONTH, 2); System.out.println("Updated Date (+2 Months) = " + calendar.getTime()); } }
Output
Current Date = Thu Nov 22 15:56:34 UTC 2018 Updated Date (+2 Months) = Tue Jan 22 15:56:34 UTC 2019
- Related Articles
- Increment a Date using the Java Calendar Class
- Decrement a Month using the Calendar Class in Java
- Display Month of Year using Java Calendar
- Create a Date object using the Calendar class in Java
- Get week of month and year using Java Calendar
- Java Program to decrement a Date using the Calendar Class
- Calendar Functions in Python - ( calendar(), month(), isleap()?)
- Getting calendar for a month in Python
- Calendar Functions in Python | Set 1( calendar(), month(), isleap()…)
- Determine day of week in month from Gregorian Calendar in Java
- How to print calendar for a month in Python?
- How to print a calendar for a month in Python
- How to print a one-month calendar of user choice using for loop in C?
- Get time in milliseconds using Java Calendar
- How to use calendar widget using the calendarView class in Android App?

Advertisements