Java Minute Calculate addOrRemoveMinutes(String set, int minutesBeforeSunset)

Here you can find the source of addOrRemoveMinutes(String set, int minutesBeforeSunset)

Description

add Or Remove Minutes

License

Open Source License

Declaration

public static String addOrRemoveMinutes(String set, int minutesBeforeSunset) throws ParseException 

Method Source Code

//package com.java2s;
/*/* w  w w .ja  v a 2  s .  c o  m*/
 * This file is subject to the terms and conditions defined in
 * file 'LICENSE.txt', which is part of this source code package.
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static String addOrRemoveMinutes(String set, int minutesBeforeSunset) throws ParseException {
        SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
        Date d = df.parse(set);

        Calendar cal = Calendar.getInstance();
        cal.setTime(d);
        cal.add(Calendar.MINUTE, minutesBeforeSunset);

        return df.format(cal.getTime());
    }
}

Related

  1. compareDateEndWithMinute(Date d1, Date d2)
  2. countTimeAfter(String date, int minute)
  3. diffOfMinutes(String begin, String end)
  4. formatDateMinutes(Date myDate, String pattern)