Class HumanDate

java.lang.Object
org.javalite.common.HumanDate

public final class HumanDate extends Object
This is a helper class for converting distance bewteen two dates to a human format, like: "two days", "three months", etc.

It was inspired by a Rails helper method: distance_of_time_in_words
Author:
Igor Polevoy
  • Method Details

    • toHumanFormat

      public static String toHumanFormat(long fromTime, long toTime)
      Generates a human representation of distance in time between two time stamps. This could take a form: "less than a minute", or "about a year".
      Parameters:
      fromTime - start timestamp. This is a representation of time in milliseconds from January 1 1970.
      toTime - end timestamp. This is a representation of time in milliseconds from January 1 1970.
      Returns:
      human representation if distance in time between fromTime and toTime.
    • toHumanFormat

      public static String toHumanFormat(long fromTime)
      This is a convenience method in addition to toHumanFormat(long, long), except the second parameter is always now.
      Parameters:
      fromTime - start date. This is a representation of time in milliseconds from January 1 1970.
      Returns:
      human imprecise representation of time difference between the fromTime and now.