How to add minutes to my Date

后端 未结 12 1271
长发绾君心
长发绾君心 2020-11-30 22:11

I have this date object:

SimpleDateFormat df = new SimpleDateFormat(\"yyyy-mm-dd HH:mm\");
Date d1 = df.parse(interviewList.get(37).getTime());
12条回答
  •  暖寄归人
    2020-11-30 22:39

    Convenience method for implementing @Pangea's answer:

    /*
    *  Convenience method to add a specified number of minutes to a Date object
    *  From: http://stackoverflow.com/questions/9043981/how-to-add-minutes-to-my-date
    *  @param  minutes  The number of minutes to add
    *  @param  beforeTime  The time that will have minutes added to it
    *  @return  A date object with the specified number of minutes added to it 
    */
    private static Date addMinutesToDate(int minutes, Date beforeTime){
        final long ONE_MINUTE_IN_MILLIS = 60000;//millisecs
    
        long curTimeInMs = beforeTime.getTime();
        Date afterAddingMins = new Date(curTimeInMs + (minutes * ONE_MINUTE_IN_MILLIS));
        return afterAddingMins;
    }
    

提交回复
热议问题