- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Java Program to add 3 months to the calendar
Firstly, you need to import the following package for Calendar class in Java
import java.util.Calendar;
Create a Calendar object and display the current date and time
Calendar calendar = Calendar.getInstance(); System.out.println("Current Date and Time = " + calendar.getTime());
Now, let us add 3 months using the calendar.add() method and Calendar.MONTH constant −
calendar.add(Calendar.MONTH, 3);
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()); // Add 3 months to the Calendar calendar.add(Calendar.MONTH, 3); System.out.println("Updated Date = " + calendar.getTime()); } }
Output
Current Date = Fri Nov 23 06:38:56 UTC 2018 Updated Date = Sat Feb 23 06:38:56 UTC 2019
- Related Articles
- Java Program to add days to current date using Java Calendar
- Java Program to subtract 40 days from the calendar
- Java Program to subtract 1 year from the calendar
- Add months to current date using Calendar.add() method in Java
- Add some months to current date using Java with MySQL?
- Java Program to decrement a Date using the Calendar Class
- How can it be possible to add 3 months interval in a MySQL date without using the word ‘Months’ with interval?
- How to add months to a date in JavaScript?
- How to add calendar events in Android App?
- Java Program to Display Dates of Calendar Year in Different Format
- Java Program to Add the two Numbers
- Java Program to subtract months from current date using Calendar.add() method
- Add the following:7 years 8 months and 8 years 9 months
- Java Program to add Period to LocalDate
- How to add calendar events in Android App using Kotlin?

Advertisements