Here you can find the source of dateAdd(int datePart, int amount, Date date)
Parameter | Description |
---|---|
datePart | the datePart to use in the calculation |
amount | amount to add to date |
date | date for adding amount to |
public static Date dateAdd(int datePart, int amount, Date date)
//package com.java2s; /*/*from w w w. j a v a 2 s .c o m*/ Copyright 2012 Juan Mart?n Runge jmrunge@gmail.com http://www.zirsi.com.ar This file is part of ZirUtils. ZirUtils is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. ZirUtils is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ZirUtils. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Calendar; import java.util.Date; public class Main { /** * Method that returns the result of date + amount for the specified datePart * using Calendar.get(int) for obtaining it * * @param datePart the datePart to use in the calculation * @param amount amount to add to date * @param date date for adding amount to * @return the result from date + amount * @see java.util.Calendar */ public static Date dateAdd(int datePart, int amount, Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(datePart, cal.get(datePart) + amount); return cal.getTime(); } }