Home » Java programs

Java program to get current date and change date by adding given number of days

In this java program, we are going to learn how to get current date and change the system’s date by adding given number of days?
Submitted by IncludeHelp, on October 29, 2017

Get current date and change it by adding given number of days using java program.

To get current system date, we are using "get()" method of "Calendar" class by specifying, current month, date and year.

And to add number of days, we are using "Calendar.add()" method.

Program to get date and change by adding days in java

import java.util.Calendar;

public class ChangeDate 
	public static void main(String[] args) 
		// creating object of calendar.
		Calendar now = Calendar.getInstance();

		// print the current date.
		System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) 
		+ "-"+ now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR));

		//adding number of days 
		now.add(Calendar.DATE, 10);

		// print date after changement.
		System.out.println("Changed date : " + (now.get(Calendar.MONTH) + 1) 
		+ "-"+ now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR));


Current date : 10-28-2017
Changed date : 11-7-2017

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.