Time Distance in hours and minutes

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

public class Main {
    static SimpleDateFormat dateFormater = new SimpleDateFormat("MM/dd/yyyy");

    public static String getTimeDistance(Date from){
        long minDist = (System.currentTimeMillis() - from.getTime())/60000;
        if(minDist <= 0){
            return  (System.currentTimeMillis() - from.getTime())/1000 + " seconds";
        }
        else if(minDist >= 60){
            return  minDist/60 + " hours";
        }
        else{
            return  minDist + " minutes";
        }
    }
}
  
Home 
  Java Book 
    Runnable examples  

Date Calendar Timestamp:
  1. Create a Date for a Particular Date
  2. Create Date from specific time span
  3. Create new date without time component
  4. Create new java.sql.Timestamp
  5. Create Date with day, month and year
  6. Create Calendar for a specific date
  7. Compute days between 2 dates
  8. Calculate the age
  9. Time Distance in hours and minutes