简体   繁体   中英

Date + days calculator

I want to create a JAVA-program that show me some dates.

A box where I insert a date. ex. 26/10/2013
Another box where I insert a number of days that I want to add to the date in the first box. And an answerbox that show the resultdate.

Ex1 . 26/10/2013 + 148 days = a date
Ex2 . 24/12/1980 + 9245 days = a date

Box1 : 26/10/2013 + Box2 : 148 = Answer : 23/03/2014



Could anyone help me ?

GregorianCalendar gcal = new GregorianCalendar(2013, Calendar.OCTOBER, 26);
gcal.add(Calendar.DATE, 148);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String answer = sdf.format(gcal.getTime());

// output in default time zone (my zone: 23/03/2014)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM