Class TimeUtils


  • public class TimeUtils
    extends Object
    • Field Detail

      • MILLISECONDS_IN_NANOSECONDS

        public static final long MILLISECONDS_IN_NANOSECONDS
        To convert milliseconds in nanoseconds
        See Also:
        Constant Field Values
    • Method Detail

      • convertInMilliseconds

        public static long convertInMilliseconds​(String duration)
        Convert a string which represents a duration. It can be composed of days, hours, minutes and seconds. Examples:

        - "1d2h3m4.5s": one day, two hours, three minutes, four seconds and 500 milliseconds

        - "2h30m": two hours and 30 minutes

        - "30.5s": 30 seconds and 500 ms

        - "180s": three minutes

        Parameters:
        duration - a String which describes the duration
        Returns:
        the duration in milliseconds
      • convertInSeconds

        public static long convertInSeconds​(String duration)
        Convert a string which represents a duration. It can be composed of days, hours, minutes and seconds. Examples:

        - "1d2h3m4.5s": one day, two hours, three minutes, four seconds and 500 milliseconds

        - "2h30m": two hours and 30 minutes

        - "30.5s": 30 seconds and 500 ms

        - "180s": three minutes

        Parameters:
        duration - a String which describes the duration
        Returns:
        the duration in seconds (floored, so 30.5s returns 30)