Here you can find the source of add(Date when, int amount, int field)
Parameter | Description |
---|---|
when | the original date |
amount | the amount to add |
field | the field to add it to (from java.util.Calendar 's fields). |
public static Date add(Date when, int amount, int field)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; public class Main { /**/* ww w . j a va 2 s . c o m*/ * Add an offset to a particular day * @param when the original date * @param amount the amount to add * @param field the field to add it to (from {@link java.util.Calendar}'s fields). * @return the date with the offset added */ public static Date add(Date when, int amount, int field) { Calendar calendar = GregorianCalendar.getInstance(TimeZone.getTimeZone("UTC")); calendar.setTime(when); calendar.add(field, amount); return calendar.getTime(); } }