
In my database i have a field StartDate and EndDate Now entering date from my jsp and fetching it in the servlet
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Date date = new Date(request.getParameter("date"));
SimpleDateFormat simpleDateformat=new SimpleDateFormat("yyyy");
System.out.println("Year: " + simpleDateformat.format(date));
String k= simpleDateformat.format(date);
}
But I have to add 4 with the year value and generate the date after 4 years of Starting Date and store it into the database

The given code is useful.
try{
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
Date d=(Date)formatter.parse("30-03-2012");
Calendar cal=Calendar.getInstance();
cal.setTime(d);
cal.add(Calendar.YEAR, 4);
String newdate = formatter.format(cal.getTime());
System.out.println(newdate);
}
catch(Exception e){}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.