Here you can find the source of timeToDeparture(String startTime)
Parameter | Description |
---|---|
String | startTime in format 2012-10-15T08:17:00 |
public static String timeToDeparture(String startTime)
//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 { /**/* ww w . j av a 2 s .c om*/ *Calculates minutes from now to a specific time in the future * @param String startTime in format 2012-10-15T08:17:00 * @return minutes to departure * */ public static String timeToDeparture(String startTime) { int diffMinutes = -1; Calendar now = Calendar.getInstance(); now.setTime(new Date()); //now.setTimeZone(TimeZone.getTimeZone("Europe/Stockholm")); 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); } }