

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 40 days 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 40 days using the calendar.add() method and Calendar.DATE constant. Set a negative value since we are decrementing here
calendar.add(Calendar.DATE, -40);
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 40 Days calendar.add(Calendar.DATE, -40); System.out.println("Updated Date = " + calendar.getTime()); } }
Output
Current Date = Thu Nov 29 18:21:27 UTC 2018 Updated Date = Fri Oct20 18:21:27 UTC 2018
- Related Questions & Answers
- Java Program to subtract 1 year from the calendar
- Java Program to add days to current date using Java Calendar
- Subtract days from current date using Calendar.DATE in Java
- How to subtract days from a date in JavaScript?
- How to subtract 30 days from the current datetime in MySQL?
- How to subtract 10 days from the current datetime in MySQL?
- Java Program to subtract year from current date
- Java Program to subtract week from current date
- Java Program to add 3 months to the calendar
- Java program to subtract two matrices.
- How to subtract number of days from a date to get the previous date in R?
- Java Program to subtract hours from current time using Calendar.add() method
- Java Program to subtract months from current date using Calendar.add() method
- Is there a way to subtract number of days from a date in MySQL?
- Java Program to decrement a Date using the Calendar Class
Advertisements