Java Day Add addDate(java.util.Date date, int day)

Here you can find the source of addDate(java.util.Date date, int day)

Description

add Date

License

Open Source License

Parameter

Parameter Description
date a parameter
day a parameter

Declaration

public static java.util.Date addDate(java.util.Date date, int day) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static java.util.Date addDate(java.util.Date date, int day) {
        java.util.Calendar c = java.util.Calendar.getInstance();
        c.setTimeInMillis(getMillis(date) + ((long) day) * 24 * 3600 * 1000);
        return c.getTime();
    }/*w w  w .  ja va2s . com*/

    public static long getMillis(java.util.Date date) {
        java.util.Calendar c = java.util.Calendar.getInstance();
        c.setTime(date);
        return c.getTimeInMillis();
    }

    public static String getTime(java.util.Date date) {
        return format(date, "HH:mm:ss");
    }

    public static String format(java.util.Date date, String format) {
        String result = "";
        try {
            if (date != null) {
                java.text.DateFormat df = new java.text.SimpleDateFormat(format);
                result = df.format(date);
            }
        } catch (Exception e) {
        }
        return result;
    }
}

Related

  1. add(int date, int days)
  2. add(String date, int day)
  3. addDate(Date d, long day)
  4. addDate(Date date, int day)
  5. addDate(String date, SimpleDateFormat format, int dayCnt)
  6. addDate(String str, int field, int dayNum)
  7. addDay(Date d, int amount)
  8. addDay(Date date, int day)