Java Minute Calculate getTravelTimeinMinutes(String startTime, String endTime)

Here you can find the source of getTravelTimeinMinutes(String startTime, String endTime)

Description

Calculates difference in minutes between two datetimes

License

Apache License

Parameter

Parameter Description
startTime in format 2012-10-15T08:17:00
endTime in format 2012-10-15T08:17:00

Return

minutes difference between startTime and endTime

Declaration

public static String getTravelTimeinMinutes(String startTime,
        String endTime) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /**/*from  w  w w . j  a  v a 2s .c  o m*/
     *Calculates difference in minutes between two datetimes
     * @param startTime in format 2012-10-15T08:17:00
     * @param endTime in format 2012-10-15T08:17:00
     * @return minutes difference between startTime and endTime
     * */
    public static String getTravelTimeinMinutes(String startTime,
            String endTime) {
        int diffMinutes = 0;
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd'T'HH:mm:ss");
        Date startDate = null, endDate = null;
        try {
            startDate = dateFormat.parse(startTime);
            endDate = dateFormat.parse(endTime);
            Calendar calStart = Calendar.getInstance();
            calStart.setTime(startDate);
            Calendar calEnd = Calendar.getInstance();
            calEnd.setTime(endDate);
            long millisTravel = calEnd.getTimeInMillis()
                    - calStart.getTimeInMillis();
            diffMinutes = ((int) millisTravel / (60 * 1000));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return String.valueOf(diffMinutes);
    }
}

Related

  1. getFutureDate(int _minutes)
  2. getIntevalMinutes(String startDate, String endDate)
  3. getTime(int minuteDelt)
  4. getTimeAddMinute(String time, int minute)
  5. getTimeInDate(int offSetInMinutes)
  6. minusMinutes(String s, long minutes)
  7. minuteBetween(Date smdate, Date bdate)
  8. minutesBetween(String from, String to, String format)
  9. minutesToHylaTime(int mins)