0

I have the following DateFormat

private static final String DATE_TIME_PATTERN = "MM/dd/YY hh:mm";
private static final DateFormat dateFormat = new SimpleDateFormat(DATE_TIME_PATTERN);

And when I try to parse a date it is being changed:

public static void main(String [] args) throws ParseException {
    Calendar futureDate = Calendar.getInstance();
    System.out.println("TODAY                   " + dateFormat.format(futureDate.getTime()));
    futureDate.add(Calendar.WEEK_OF_MONTH, 4);
    String todayPlusFourWeeks = dateFormat.format(futureDate.getTime());

    System.out.println("TODAY + 4 weeks         " + todayPlusFourWeeks);

    Calendar futureDate2 = Calendar.getInstance();
    futureDate2.setTime(dateFormat.parse(todayPlusFourWeeks));


    System.out.println("TODAY + 4 weeks         " + dateFormat.format(futureDate2.getTime()));
}

I got:

TODAY                   07/22/15 05:46
TODAY + 4 weeks         08/19/15 05:46
TODAY + 4 weeks         12/28/15 05:46

In the third print I'm getting 12/28/15 05:46 ? What I'm missing at the moment of parsing that String ?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Federico Lenzi
  • 1,632
  • 4
  • 18
  • 34

0 Answers0