Home » Java programs » Java date, time programs

Java program to print different dates of days like today, yesterday and tomorrow

In this java program, we have to print the different dates of days. Here we are using package java.time.Localdate for using the method and class of this package.
Submitted by IncludeHelp, on December 04, 2017

We are here taking three days like date, yesterday and tomorrow.


import java.time.LocalDate;  

public class ExDate
	public static void main(String[] args)
		// create objects of the different dates.
		LocalDate date = LocalDate.now();  
		LocalDate yesterday = date.minusDays(1);  
		LocalDate tomorrow = yesterday.plusDays(2);
		// print today,yesterday and tomorrow date.
		System.out.println("Today date is : "+date);  
		System.out.println("Yesterday date is : "+yesterday);  
		System.out.println("Tommorow date is : "+tomorrow);  


Today date is : 2017-11-30
Yesterday date is : 2017-11-29
Tommorow date is : 2017-12-01

In this example, we are going to print the dates of different days. For print dates, we are creating an object of LocalDate class this class represents date in default format 'yyyy-mm-dd'. This is given in java package that LocalDate date = LocalDate.now() will be used for present date (today), LocalDate yesterday =date.minusDays(1) will return a copy of LocalDate with specified number of days subtracted.

And LocalDate tomorrow = yesterday.plusDays(2) will return a copy of LocalDate with specified number of days added.

After that print these days System.out.println("Today date is : "+date) for present date , System.out.println("Yesterday date is : "+yesterday) for yesterday System.out.println("Tomorrow date is : "+tomorrow) for tomorrow .

Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.

Comments and Discussions

We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.