Java Date Add add(Date date, int field, int diff)

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

Description

add

License

Apache License

Declaration

public static Date add(Date date, int field, int diff) 

Method Source Code

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

import java.util.*;

public class Main {
    /**/*  w ww . j a  v a2  s .c o m*/
     * @since 2008-01-02
     */
    public static Date add(Date date, int field, int diff) {
        Calendar c = getCalendar(date);
        c.add(field, diff);
        return c.getTime();
    }

    /**
     * @since 2008-01-02
     */
    public static Date add(int field, int diff) {
        return add(new Date(), field, diff);
    }

    /**
     * @since 2008-01-02
     */
    public static Calendar getCalendar(long millis) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(millis);
        return c;
    }

    /**
     * @since 2008-01-02
     */
    public static Calendar getCalendar(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c;
    }
}

Related

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