- 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 decrement a Date using the Calendar Class
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 decrement the date using the add() method and Calendar.DATE constant. Set a negative value since we are decrementing the date
calendar.add(Calendar.DATE, -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()); // Decrementing date by 3 calendar.add(Calendar.DATE, -3); System.out.println("Updated Date = " + calendar.getTime()); } }
Output
Current Date = Thu Nov 22 15:55:02 UTC 2018 Updated Date = Mon Nov 19 15:55:02 UTC 2018
- Related Articles
- Decrement a Month using the Calendar Class in Java
- Increment a Date using the Java Calendar Class
- Create a Date object using the Calendar class in Java
- Java Program to add days to current date using Java Calendar
- Increment a Month using the Calendar Class in Java
- JavaScript program to decrement a date by 1 day
- Compare date time using after() method of Java Calendar
- Compare date time using before() method of Java Calendar
- How to print date using GregorianCalendar class in Java?
- Set the Date and Time with Gregorian Calendar in Java
- Java Program to add 3 months to the calendar
- Java Program to subtract 40 days from the calendar
- Java Program to subtract 1 year from the calendar
- How to use calendar widget using the calendarView class in Android App?
- How to use Calendar Widget using the CalendarView class in Android App using Kotlin?

Advertisements