Source Code : Time Distance

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Time Distance

     
//package com.ctrcv.util;

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

public class DateUtil {
  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";      
    }
  }

  public static Date fromDateStr(String date) {
    try {
      return dateFormater.parse(date);
    } catch (Exception e) {
      return null;
    }
  }
}

   
    
    
    
    
  

Thank with us