public static String addDate(String fromDate, String format, int addYear, int addMonth, int addDate, int addHour, int addMinute, int addSecond) throws ParseException {

    SimpleDateFormat sdf = new SimpleDateFormat(format);

    Date date = sdf.parse(fromDate);

    Calendar cal = new GregorianCalendar();


    cal.setTime(date);

    cal.add(Calendar.YEAR, +addYear);

    cal.add(Calendar.MONTH, +addMonth);

    cal.add(Calendar.DATE, +addDate);

    cal.add(Calendar.HOUR, +addHour);

    cal.add(Calendar.MINUTE, +addMinute);

    cal.add(Calendar.SECOND, +addSecond);


    SimpleDateFormat sdf2 = new SimpleDateFormat(format);

    String toDate = sdf2.format(cal.getTime());


    return toDate;

  }


  1년 후

  String addDate(format, "yyyy-MM-dd HH:mm:ss", 1, 0, 0, 0, 0, 0);

  10분 후

  String addDate(format, "yyyy-MM-dd HH:mm:ss", 0, 0, 0, 0, 10, 0);

+ Recent posts