OAF : How to Add days in input date
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.text.ParseException;
public class Example{
public static void main(String args[]){
String oldDate = "2017-01-29";
System.out.println("Date before Addition: "+oldDate);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
try{
c.setTime(sdf.parse(oldDate));
}catch(ParseException e){
e.printStackTrace();
}
//Incrementing the date by 1 day
c.add(Calendar.DAY_OF_MONTH, 1);
String newDate = sdf.format(c.getTime());
System.out.println("Date Incremented by One: "+newDate);
}
}
No comments:
Post a Comment