CodesJava

Easy learning with example program codes

Java add days to current date


Java add days to current date example

package com.codesjava;
 
import java.util.Calendar;
 
public class CalenderTest {
	public static void main(String args[]){
	   Calendar calendar = Calendar.getInstance();  
	   System.out.println("The current date is : " + calendar.getTime());  
	   calendar.add(Calendar.DATE, 10);  
	   System.out.println("10 days later: " + calendar.getTime());  
	   calendar.add(Calendar.MONTH, 3);  
	   System.out.println("3 months later: " + calendar.getTime());  
	   calendar.add(Calendar.YEAR, 4);  
	   System.out.println("4 years later: " + calendar.getTime()); 
	   int maximum = calendar.getMaximum(Calendar.DAY_OF_WEEK);  
	   System.out.println("Maximum number of days in week: " + maximum);  
	   maximum = calendar.getMaximum(Calendar.WEEK_OF_YEAR);  
	   System.out.println("Maximum number of weeks in year: " + maximum);  
	   int minimum = calendar.getMinimum(Calendar.DAY_OF_WEEK);  
	   System.out.println("Minimum number of days in week: " + minimum);  
	   minimum = calendar.getMinimum(Calendar.WEEK_OF_YEAR);  
	   System.out.println("Minimum number of weeks in year: " + minimum);  
	}
}

Output:

The current date is : Mon Apr 09 23:33:23 IST 2018
10 days later: Thu Apr 19 23:33:23 IST 2018
3 months later: Thu Jul 19 23:33:23 IST 2018
4 years later: Tue Jul 19 23:33:23 IST 2022
Maximum number of days in week: 7
Maximum number of weeks in year: 53
Minimum number of days in week: 1
Minimum number of weeks in year: 1
Posted in Date   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki