- 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
Java Program to subtract 1 year from 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 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 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()); // Subtract 1 year from the Calendar calendar.add(Calendar.YEAR, -1); System.out.println("Updated Date = " + calendar.getTime()); } }
Output
Current Date = Fri Nov 23 06:39:40 UTC 2018 Updated Date = Thu Nov 23 06:39:40 UTC 2017
- Related Articles
- Java Program to subtract 40 days from the calendar
- Java Program to subtract year from current date
- Java Program to Display Name of the Weekdays in Calendar Year
- Java Program to Display Dates of Calendar Year in Different Format
- Java Program to Display Name of Months of Calendar Year in Short Format
- Display Month of Year using Java Calendar
- Java Program to subtract week from current date
- Java Program to Get Year from Date
- Write the difference between calendar year and fiscal year.
- Get week of month and year using Java Calendar
- Java Program to display previous year from GregorianCalendar
- Java Program to add 3 months to the calendar
- Java Program to subtract hours from current time using Calendar.add() method
- Java Program to subtract months from current date using Calendar.add() method
- Find the next identical calendar year in C++

Advertisements