- 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
Found 4338 Articles for Java 8
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
Firstly, you need to import the following package for Calendar class in Javaimport java.util.Calendar;Create a Calendar object and display the current date and timeCalendar calendar = Calendar.getInstance(); System.out.println("Current Date and Time = " + calendar.getTime());Now, let us subtract 1 year using the calendar.add() method and Calendar.YEAR constant. Set a negative value since we are decrementing here −calendar.add(Calendar.YEAR, -1);The following is an exampleExample Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println("Current Date = " + calendar.getTime()); // Subtract 1 year from the ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
641 Views
Firstly, you need to import the following package for Calendar class in Javaimport java.util.Calendar;Create a Calendar object and display the current date and timeCalendar 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 exampleExample Live Demoimport 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); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
255 Views
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 timeCalendar calendar = Calendar.getInstance(); System.out.println("Current Date and Time = " + calendar.getTime());Now, let us subtract 40 days using the calendar.add() method and Calendar.DATE constant. Set a negative value since we are decrementing herecalendar.add(Calendar.DATE, -40);The following is an exampleExample Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println("Current Date = " + calendar.getTime()); // Subtract 40 Days ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
Firstly, you need to import the following package for Calendar class in Javaimport java.util.Calendar;Create a Calendar object and display the current date and timeCalendar calendar = Calendar.getInstance(); System.out.println("Current Date and Time = " + calendar.getTime());Now, let us decrement the year using the calendar.add() method and Calendar.YEAR constant. Set a negative value since we are decrementing herecalendar.add(Calendar.YEAR, -20);The following is an exampleExample Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println("Current Date = " + calendar.getTime()); // Subtract 20 Years ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
919 Views
Firstly, you need to import the following package for Calendar class in Javaimport java.util.Calendar;Create a Calendar object and display the current date and timeCalendar calendar = Calendar.getInstance(); System.out.println("Current Date and Time = " + calendar.getTime());Now, let us add year using the calendar.add() method and Calendar.YEAR constantcalendar.add(Calendar.YEAR, 20);The following is an exampleExample Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println("Current Date = " + calendar.getTime()); // Add 20 Years calendar.add(Calendar.YEAR, 20); System.out.println("Updated Date = " + ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
Import the following package for Calendar class in Javaimport java.util.Calendar;Firstly, create a Calendar object and display the current date and timeCalendar calendar = Calendar.getInstance(); System.out.println("Current Date and Time = " + calendar.getTime());Now, let us increment the weeks using the calendar.add() method and Calendar.WEEK_OF_YEAR constant.calendar.add(Calendar.WEEK_OF_YEAR, 2);The following is an exampleExample Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println("Current Date = " + calendar.getTime()); // Adding 2 weeks calendar.add(Calendar.WEEK_OF_YEAR, 2); System.out.println("Updated Date = " + calendar.getTime()); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
445 Views
Import the following package for Calendar class in Javaimport java.util.Calendar;Firstly, create a Calendar object and display the current date and timeCalendar calendar = Calendar.getInstance(); System.out.println("Current Date and Time = " + calendar.getTime());Now, let us decrement the seconds using the calendar.add() method and Calendar.SECOND constant. Set a negative value since we are decrementingcalendar.add(Calendar.SECOND, -20);The following is an exampleExample Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println("Current Date = " + calendar.getTime()); // Subtract 20 seconds from current date calendar.add(Calendar.SECOND, ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
777 Views
Import the following package for Calendar class in Javaimport java.util.Calendar;Firstly, create a Calendar object and display the current dateCalendar calendar = Calendar.getInstance(); System.out.println("Current Date = " + calendar.getTime());Now, let us add days using the add() method and Calendar.DATE constantcalendar.add(Calendar.DATE, 2);The following is an exampleExample Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println("Current Date = " + calendar.getTime()); // Incrementing Days by 2 calendar.add(Calendar.DATE, 2); System.out.println("Updated Date = " + calendar.getTime()); } }OutputCurrent Date = ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
168 Views
Import the following package for Calendar class in Javaimport java.util.Calendar;Firstly, create a Calendar object and display the current dateCalendar calendar = Calendar.getInstance(); System.out.println("Current Date = " + calendar.getTime());Now, let us decrement the month using the add() method and Calendar.MONTH constant. Set a negative value here since we are decrementingcalendar.add(Calendar.MONTH, -2);The following is an exampleExample Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println("Current Date = " + calendar.getTime()); // Decrementing Month by 2 calendar.add(Calendar.MONTH, -2); System.out.println("Updated ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
396 Views
Import the following package for Calendar class in Javaimport java.util.Calendar;Firstly, create a Calendar object and display the current dateCalendar 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 exampleExample Live Demoimport 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()); ... Read More