Java Day Add addDate(Date d, long day)

Here you can find the source of addDate(Date d, long day)

Description

add Date

License

Open Source License

Declaration

public static Date addDate(Date d, long 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 addDate(Date d, long day) {
        long time = d.getTime();
        day = day * 24 * 60 * 60 * 1000;
        time += day;/*from  www  . j  av a 2s. c om*/
        return new Date(time);
    }

    public static long getTime() {
        java.util.Date dt = new java.util.Date();
        return dt.getTime();
    }

    public static String getTime(String s) {
        if (s == null || s.equals(""))
            return "";
        String s1 = "";
        try {
            SimpleDateFormat simpledateformat = new SimpleDateFormat(s);
            s1 = simpledateformat.format(Calendar.getInstance().getTime());
        } catch (Exception exception) {
            System.out.println(Calendar.getInstance().toString() + "cannot format time [function:getTime(String)]");
            exception.printStackTrace();
        }
        return s1;
    }
}

Related

  1. add(int date, int days)
  2. add(String date, int day)
  3. addDate(Date date, int day)
  4. addDate(java.util.Date date, int day)
  5. addDate(String date, SimpleDateFormat format, int dayCnt)
  6. addDate(String str, int field, int dayNum)