add Minutes To Date - Java java.util

Java examples for java.util:Minute

Description

add Minutes To Date

Demo Code


//package com.java2s;
import java.util.Date;

public class Main {
    public static void main(String[] argv) throws Exception {
        int minutes = 2;
        Date beforeTime = new Date();
        System.out.println(addMinutesToDate(minutes, beforeTime));
    }/*from w ww .ja  v a2s  .c o m*/

    static final long ONE_MINUTE_IN_MILLIS = 60000;

    public static Date addMinutesToDate(int minutes, Date beforeTime) {

        long curTimeInMs = beforeTime.getTime();
        Date afterAddingMins = new Date(curTimeInMs
                + (minutes * ONE_MINUTE_IN_MILLIS));
        return afterAddingMins;
    }
}

Related Tutorials