-1

Can anyone tell me why this test is failing? I tried normal Java Date util and it also gave me the same result.

java.lang.AssertionError: expected: Wed Jan 01 00:07:00 CET 2014 but was: Fri Jan 31 00:06:00 CET 2014

public static Date addDaysToDate(Date fromDate, int days){       
    DateTime dateTime = new DateTime(fromDate);
    return dateTime.plusDays(days).toDate();
}

@Test
public void test() throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
    Date fromDate = sdf.parse("2014-06-30");

    Date toDate = DateUtil.addDaysToDate(fromDate, 1);
    assertEquals(sdf.parse("2014-07-01"), toDate);
}
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
TheCoder
  • 8,413
  • 15
  • 42
  • 54
  • possible duplicate of [how to convert mm/dd/yyyy to yyyy-mm-dd in java](http://stackoverflow.com/questions/22111209/how-to-convert-mm-dd-yyyy-to-yyyy-mm-dd-in-java) – Basil Bourque Jun 24 '14 at 17:48

1 Answers1

6

You need to consult the API Docs and ensure that the format you are using is correct for the data you are parsing...

Change yyyy-mm-dd to yyyy-MM-dd

mm is used for minutes

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366