Java Date Add add(Date date, long minutes)

Here you can find the source of add(Date date, long minutes)

Description

add

License

Open Source License

Declaration

public static Date add(Date date, long minutes) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static final int MINUTE = 2;

    public static Date add(Date date, long minutes) {
        if (date == null) {
            throw new IllegalArgumentException();
        }/*  w w w .  j a  va  2 s .  c o  m*/

        return addMinutes(date, minutes);
    }

    public static java.util.Date addMinutes(java.util.Date date, long... minutes) {
        if (minutes == null) {
            return date;
        }
        java.util.Calendar c = java.util.Calendar.getInstance();
        c.setTime(date);
        for (long minute : minutes) {
            c.add(Calendar.MINUTE, (int) minute);
        }

        return c.getTime();
    }

    public static Date addMinutes(Date date, long minutes) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(getMillis(date) + ((long) minutes) * 60 * 1000);
        return c.getTime();
    }

    public static long getMillis(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.getTimeInMillis();
    }
}

Related

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