-2

I need to add X no of days to today. So far I have researched most of the questions in stackoverflow and I have tried the following code:

GregorianCalendar today = new GregorianCalendar();
today.setTime(Calendar.getInstance().getTime());
today.add(Calendar.DAY_OF_YEAR,100);//I have also tried Calendar.DATE too

SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-DD"); 
String currentDate = formatter.format(today.getTime());     
System.out.println(currentDate);

When I see the Current Date, I see the month is displayed correctly, but the Date is incorrect. In the above example, I am seeing 2014-04-103 as the output.

I also want the correct date. Please help.

Thanks.

user3010197
  • 47
  • 1
  • 1
  • 5
  • Did you read the javadoc? What does `DD` stand for in your pattern? – Sotirios Delimanolis Jan 04 '14 at 02:31
  • You should have used the google query: "adding days to date in java" which gets you one of the hundreds of times this question has been answered on stack overflow: [adding days to a date in JAVA](http://stackoverflow.com/questions/12087419/adding-days-to-a-date-in-java) – Eric Leschinski Jan 04 '14 at 02:39

1 Answers1

0

DD is day in year so its the 103rd day of the year.- you want dd for day in month

jkhouw1
  • 7,320
  • 3
  • 32
  • 24