minus Minutes To Date - Java java.util

Java examples for java.util:Minute

Description

minus 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(minusMinutesToDate(minutes, beforeTime));
    }/*from   w  w w.  j  a  v  a2  s .c  om*/

    static final long ONE_MINUTE_IN_MILLIS = 60000;

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

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

Related Tutorials