Here you can find the source of addDay(Date date, int days)
The calculation of the date of increase, reducing the number of days of the date.License
Open Source LicenseParameter
Parameter | Description |
---|---|
date | target date |
days | variable number |
public static Date addDay(Date date, int days)
//package com.java2s; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { /**/*from w w w . jav a2s . c o m*/ * <pre> * The calculation of the date of increase, reducing the number of days of the date. * days is a positive number that when added, is negative for the reduction * * DateUtils.addDay(1970-01-01, 1) = 1970-01-02 * </pre> * * @param date target date * @param days variable number * @return Date */ public static Date addDay(Date date, int days) { if (date == null) { return null; } Calendar c = getCalendar(date); c.add(Calendar.DATE, days); return c.getTime(); } /** * get GregorianCalendar. * * @return Calendar,GregorianCalendar. */ public static Calendar getCalendar() { return new GregorianCalendar(); } /** * get GregorianCalendar with given date. * * @param date Date. * @return Calendar, GregorianCalendar. */ public static Calendar getCalendar(Date date) { Calendar calendar = getCalendar(); calendar.setTime(date); return calendar; } }