Add n number of days to given date
Add n number of days to given date
public static void main(String args[]) throws Exception {
SetTest st = new SetTest();
st.addDaysToDate("11/11/2007", 2);
}
private void addDaysToDate(String date, int daysToAdd) throws Exception {
Date todayDate = new Date();
DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String strDate = sdf.format(todayDate);
Date parsedDate = sdf.parse(date);
System.out.println(strDate);
System.out.println(parsedDate);
Calendar now = Calendar.getInstance();
now.setTime(parsedDate);
now.add(Calendar.DAY_OF_MONTH, daysToAdd);
System.out.println(now.getTime());
}
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.