Java Date Add add(Date date, int field, long amount)

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

Description

Adds the specified (signed) amount of time to the given time field, based on the calendar's rules.

License

Apache License

Parameter

Parameter Description
date the date
field the field
amount the amount

Return

the date

Declaration

public static Date add(Date date, int field, long amount) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**//from   w ww .j a  v  a  2 s.  c  om
     * Adds the specified (signed) amount of time to the given time field, based
     * on the calendar's rules.
     * 
     * @param date
     *            the date
     * @param field
     *            the field
     * @param amount
     *            the amount
     * @return the date
     */
    public static Date add(Date date, int field, long amount) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(field, (int) amount);
        return calendar.getTime();
    }
}

Related

  1. add(Date date, int calendarField, int amount)
  2. add(Date date, int field, int amount)
  3. add(Date date, int field, int amount)
  4. add(Date date, int field, int diff)
  5. add(Date date, int field, int value)
  6. add(Date date, int x)
  7. add(Date date, long minutes)
  8. add(Date eredeti, int mihez, int mennyit)
  9. add(Date when, int amount, int field)