Class Durations


  • public class Durations
    extends Object
    Utility class to handle human readable time durations.
    • Constructor Detail

      • Durations

        public Durations()
    • Method Detail

      • 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"
      • humanize

        public static String humanize​(long time)
        Converts a time in miliseconds to human readable duration in the format "Xd Xh Xm Xs Xms"
      • humanize

        public static String humanize​(long time,
                                      String separator)
      • 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

        @Deprecated
        public static String fromDuration​(Duration duration)
        Deprecated.
        Converts a time from java.util.time.Duration to human readable format "Xd Xh Xm Xs Xms" (for interoperability).
        TODO broken: https://stackoverflow.com/questions/24491243/why-cant-i-get-a-duration-in-minutes-or-hours-in-java-time