Here you can find the source of add(Date date, int field, int amount)
Parameter | Description |
---|---|
date | The date to perform the arithmetic function on |
field | A Calendar constant to retrieve the field value from the Date object. Same as for #get get() . |
amount | the amount of date or time to be added to the field |
public static Date add(Date date, int field, int amount)
//package com.java2s; /*// ww w .ja va 2 s . c o m * CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF * Institute of Systems Science, National University of Singapore * * Copyright 2012 Team 4(Part-Time), ISS, NUS, Singapore. All rights reserved. * Use of this source code is subjected to the terms of the applicable license * agreement. * * ----------------------------------------------------------------- * REVISION HISTORY * ----------------------------------------------------------------- * DATE AUTHOR REVISION DESCRIPTION * 10 March 2012 Chen Changfeng 0.1 Class creating * * * * * */ import java.util.*; public class Main { /** * Date Arithmetic function. Adds the specified (signed) amount of time to * the given time field, based on the calendar's rules. * <p> * For example, to subtract 5 days from a specific date, it can be achieved * by calling: <p> * DateUtil.add(date, Calendar.DATE, -5). * <p> * @param date The date to perform the arithmetic function on * @param field A Calendar constant to retrieve the field value from the Date * object. Same as for {@link #get get()}. * @param amount the amount of date or time to be added to the field * @return The date as a result of the execution of the arithmetic function. */ public static Date add(Date date, int field, int amount) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(field, amount); return cal.getTime(); } }