Java Minute Add addMinutes(java.util.Date date, long... minutes)

Here you can find the source of addMinutes(java.util.Date date, long... minutes)

Description

add Minutes

License

Open Source License

Declaration

public static java.util.Date addMinutes(java.util.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 java.util.Date addMinutes(java.util.Date date, long... minutes) {
        if (minutes == null) {
            return date;
        }// ww w .j  av  a  2 s .com
        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 Date add(Date date, long minutes) {
        if (date == null) {
            throw new IllegalArgumentException();
        }

        return addMinutes(date, minutes);
    }

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

Related

  1. addMinutes(Date date, int minutes)
  2. addMinutes(Date in, int minutes)
  3. addMinutes(Date t, int minutes)
  4. addMinutesToDate(Date initialDateInMillis, Integer minutesToAdd)
  5. addMinutesToDate(final Date d, final int minutes)