0
    String dateSample = "2016-09-30 21:59:22.2500000";

    String oldFormat = "yyyy-MM-dd HH:mm:ss";
    String newFormat = "MM-dd-yyyy";

    SimpleDateFormat sdf1 = new SimpleDateFormat(oldFormat);
    SimpleDateFormat sdf2 = new SimpleDateFormat(newFormat);

    sdf2.format(sdf1.parse(dateSample));

From this, I got 09-30-2016 But, I want the result 09-28-2016 How to do it?

AAP
  • 13
  • 1
  • 5

1 Answers1

0
Calendar cal = GregorianCalendar.getInstance();
cal.setTime( sdf1.parse(dateSample));
cal.add( GregorianCalendar.DAY_OF_MONTH, -2); // date manipulation
System.out.println(sdf2.format(cal.getTime())); 

Hope I helped

Shay Gold
  • 403
  • 4
  • 14