Java Date Add add(Date when, int amount, int field)

Here you can find the source of add(Date when, int amount, int field)

Description

Add an offset to a particular day

License

Open Source License

Parameter

Parameter Description
when the original date
amount the amount to add
field the field to add it to (from java.util.Calendar 's fields).

Return

the date with the offset added

Declaration

public static Date add(Date when, int amount, int field) 

Method Source Code


//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();
    }
}

Related

  1. add(Date date, int field, int value)
  2. add(Date date, int field, long amount)
  3. add(Date date, int x)
  4. add(Date date, long minutes)
  5. add(Date eredeti, int mihez, int mennyit)
  6. add(int datePart, int detal, Date date)
  7. add(int field, int value, Date fromDate)
  8. add(long date, int field, int amount)
  9. add30Minutes(Date date)