Java tutorial
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String timeToDeparture(String startTime) { int diffMinutes = -1; Calendar now = Calendar.getInstance(); now.setTime(new Date()); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); Date date = null; try { date = dateFormat.parse(startTime); } catch (ParseException e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); cal.setTime(date); long millisDiff = cal.getTimeInMillis() - now.getTimeInMillis(); if (millisDiff > 0) { diffMinutes = ((int) millisDiff / (60 * 1000)); } return String.valueOf(diffMinutes); } }