Java Date Add addDate(Date date, int k)

Here you can find the source of addDate(Date date, int k)

Description

add Date

License

Apache License

Declaration

public static String addDate(Date date, int k) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static String addDate(Date date, int k) {
        java.util.Calendar cal = Calendar.getInstance();
        cal.setTime(date);/*from   w ww  .ja va2s .c  o m*/
        cal.add(Calendar.DATE, k);
        return format(cal.getTime());
    }

    public static String format(Date date, String pattern) {
        if (date == null) {
            return null;
        }
        SimpleDateFormat sf = new SimpleDateFormat(pattern);
        return sf.format(date);
    }

    public static String format(Date date) {
        return format(date, "yyyy-MM-dd");
    }
}

Related

  1. add30Minutes(Date date)
  2. addCertainTime(java.util.Date date, double hours)
  3. addDate(Date date, int add)
  4. addDate(Date date, int amount, int type)
  5. addDate(Date date, int field, int add)
  6. addDate(Date date, int noOfDays)
  7. addDate(Date date, int years, int months, int days)
  8. addDate(Date date, String unit, int quantity)
  9. addDate(int field, int amount)