Monday, May 9, 2011

Adding ndays to given Date

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

       /**
         * @param date
         * @param days
         * @param format
         * @return

         */
        public static String addDays(Date date, Integer days, String format) {

                String formattedDate = null;
                if(null != date && null != format){
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTime(date);
                        calendar.add(Calendar.DATE, days);

                        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
                        formattedDate = dateFormat.format(calendar.getTime());
                }
              
                return formattedDate;
        }
      


No comments:

Post a Comment