Java Day Add addDay(Date date, int day)

Here you can find the source of addDay(Date date, int day)

Description

add Day

License

Open Source License

Declaration

public static Date addDay(Date date, int day) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static Date addDay(Date date, int day) {

        Calendar c = Calendar.getInstance();
        c.setTime(date);/*from   w  w w . j  a  va 2s  .c  om*/

        c.add(Calendar.DAY_OF_MONTH, day);

        return c.getTime();
    }

    public static String getTime(Calendar c) {
        return getDate(c.getTime(), "HH:mm:ss");
    }

    public static String getDate() {
        return getDate(getCurDate(), "yyyy-MM-dd");
    }

    public static String getDate(Date date, String format) {

        String dtstr = "";
        if (date == null) {
            return dtstr;
        }

        if (format == null || "".equals(format.trim())) {
            format = "yyyy-MM-dd";
        }

        SimpleDateFormat sdf = new SimpleDateFormat(format);
        dtstr = sdf.format(date);
        return (dtstr == null ? "" : dtstr);

    }

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

    public static Date getDate(long time) {

        Calendar c = getCurCalendar();
        c.setTimeInMillis(time);

        return c.getTime();
    }

    public static Date getCurDate() {
        return getCurCalendar().getTime();
    }

    public static Calendar getCurCalendar() {
        return Calendar.getInstance();
    }
}

Related

  1. addDate(java.util.Date date, int day)
  2. addDate(String date, SimpleDateFormat format, int dayCnt)
  3. addDate(String str, int field, int dayNum)
  4. addDay(Date d, int amount)
  5. addDay(Date date, int day)
  6. addDay(Date date, int dayAmount)
  7. addDay(Date date, int days)
  8. addDay(Date date, int n)
  9. addDay(Date date, int num)