Time Distance : Time « Development Class « Java






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;
    }
  }
}

   
    
    
    
    
  








Related examples in the same category

1.Get Time From Date
2.ISO8601 Date Time Format
3.Time Format
4.Time Formatter
5.Returns time string
6.Returns the given date with the time values cleared
7.Convert the time to the midnight of the currently set date
8.Compare both times and dates
9.Tells you if the date part of a datetime is in a certain time range
10.Returns the given date with time set to the end of the day
11.Convert milliseconds to readable string
12.Determines whether or not a date has any time values (hour, minute, seconds or millisecondsReturns the given date with the time values cleared
13.Returns a formatted String from time
14.Time library
15.Elapsed time in hours/minutes/seconds
16.Sets the time on the same day to 00:00:00.000
17.Determines if given times span at least an entire day
18.Converts a given time in milliseconds into a XMLGregorianCalendar object.
19.Time Formatter
20.Format time
21.A utility class for representing a span of time.
22.GmtCalendar is a useful class for working with times that are based using GMT time.
23.Time Period
24.Represents the TSTInfo strcture within a time-stamp token (RFC 3161).
25.SimpleTimer enables bounded and unbounded waits.
26.Takes a time in milliseconds and returns an hours, minutes and seconds representation.
27.Format time in milliseconds