Class Durations

java.lang.Object
de.galan.commons.time.Durations

public class Durations extends Object
Utility class to handle human readable time durations.
  • Field Details

  • Constructor Details

    • Durations

      public Durations()
  • Method Details

    • timeLeft

      public static String timeLeft(Date date)
      Prints how long the given date is in the future in the format "Xd Xh Xm Xs Xms"
    • timeLeft

      public static String timeLeft(Instant date)
      Prints how long the given date is in the future in the format "Xd Xh Xm Xs Xms"
    • timeAgo

      public static String timeAgo(Date date)
      Prints how long the given date is ago in the format "Xd Xh Xm Xs Xms"
    • timeAgo

      public static String timeAgo(Instant date)
      Prints how long the given date is ago in the format "Xd Xh Xm Xs Xms"
    • timeAgo

      protected static String timeAgo(Instant date, Instant reference)
    • humanize

      public static String humanize(long time)
      Converts a time in miliseconds to human readable duration in the format "XdXhXmXsXms"
    • humanize

      public static String humanize(Duration duration)
    • humanize

      public static String humanize(Duration duration, String separator)
    • humanize

      public static String humanize(long time, String separator)
      Converts a time in miliseconds to human readable duration in the format "Xd Xh Xm Xs Xms" (example when the separator is a SPACE).
    • dehumanize

      public static Long dehumanize(String time)
      Converts a human readable duration in the format "Xd Xh Xm Xs Xms" to miliseconds.
    • toDuration

      public static Duration toDuration(String time)
      Converts a time in human readable format "Xd Xh Xm Xs Xms" to java.util.time.Duration (for interoperability).
    • fromDuration

      public static String fromDuration(Duration duration)
      Converts a time from java.util.time.Duration to human readable format "Xd Xh Xm Xs Xms" (for interoperability).