- 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 display previous day from GregorianCalender
For GregorianCalendar class, import the following package.
import java.util.GregorianCalendar;
Create an object.
GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();
Now, use the following field and add() method with a negative one (-1) to display the previous day.
cal.add((GregorianCalendar.DATE), -1)
Example
import java.util.Calendar; import java.util.GregorianCalendar; public class Demo { public static void main(String[] a) { GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance(); System.out.println("Current date: " + cal.getTime()); // past date cal.add((GregorianCalendar.DATE), -1); System.out.println("Modified date (Previous Day): " + cal.getTime()); } }
Output
Current date: Mon Nov 19 18:12:53 UTC 2018 Modified date (Previous Day): Sun Nov 18 18:12:53 UTC 2018
- Related Articles
- C# program to display the previous day
- Java Program to display previous year from GregorianCalendar
- Java Program to display previous month from GregorianCalendar
- Java Program to get the previous node from a JTree
- Java program to get the previous sibling from a JTree
- Java Program to get the previous leaf from a JTree
- Java Program to display date with day name in short format
- Get all MySQL records from the previous day (yesterday)?
- C# program to display the next day
- Java Program to get display name for Day of Week in different locale
- Java Program to display past date from GregorianCalendar
- How to get the previous day with MySQL CURDATE()?
- Display two digits day number in Java
- Java Program to get the day of the week from GregorianCalendar
- Display Day Name of Week using Java Calendar

Advertisements