Java Day Add addDay(Date d, int amount)

Here you can find the source of addDay(Date d, int amount)

Description

add Day

License

Apache License

Declaration

public static Date addDay(Date d, int amount) 

Method Source Code

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

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

public class Main {

    public static Date addDay(Date d, int amount) {
        return add(d, Calendar.DATE, amount);
    }// w w  w .  j  a v  a  2 s  .  co  m

    public static Date add(Date d, int field, int amount) {
        if (d == null) {
            return null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(d);
        calendar.add(field, amount);
        return calendar.getTime();
    }

    public static Date getTime(String date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.parse(date);
    }
}

Related

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