Here you can find the source of getTravelTimeinMinutes(String startTime, String endTime)
Parameter | Description |
---|---|
startTime | in format 2012-10-15T08:17:00 |
endTime | in format 2012-10-15T08:17:00 |
public static String getTravelTimeinMinutes(String startTime, String endTime)
//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); } }