Java Minute Calculate minusMinutes(String s, long minutes)

Here you can find the source of minusMinutes(String s, long minutes)

Description

minus Minutes

License

Open Source License

Declaration

static public String minusMinutes(String s, long minutes) throws Exception 

Method Source Code

//package com.java2s;
//   Licensed under the Apache License, Version 2.0 (the "License"); you may

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    static public String minusMinutes(String s, long minutes) throws Exception {
        if (!s.contains(" "))
            throw new Exception();

        Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(s);

        //minus x minutes
        long time = date.getTime() - (minutes * 10000L);
        //reset time to 1 minute ago
        date.setTime(time);/*from w  w  w. jav a 2s. c  o m*/

        //create formatter
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

        //return date in original format
        return sf.format(date);
    }
}

Related

  1. getIntevalMinutes(String startDate, String endDate)
  2. getTime(int minuteDelt)
  3. getTimeAddMinute(String time, int minute)
  4. getTimeInDate(int offSetInMinutes)
  5. getTravelTimeinMinutes(String startTime, String endTime)
  6. minuteBetween(Date smdate, Date bdate)
  7. minutesBetween(String from, String to, String format)
  8. minutesToHylaTime(int mins)
  9. plusMinute(Date date, int minutes)