Class TimeUtil

java.lang.Object
org.cloudbus.cloudsim.util.TimeUtil

public final class TimeUtil extends Object
Utility class that provides some methods to deal with time units. It's not used the Duration and Period classes because they don't work with double type. Therefore, it's not possible for them to deal with time fractions, such as 2.5 hours.
Since:
CloudSim Plus 4.4.2
Author:
Manoel Campos da Silva Filho
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    Gets the computer actual time in seconds.
    static double
    daysToHours(double days)
    Converts a value in days to hours.
    static double
    daysToSeconds(double days)
    Converts a value in days to seconds.
    static double
    elapsedSeconds(double startTimeSeconds)
    Gets the real elapsed time from the given time in seconds.
    static long
    elapsedSeconds(long startTimeSeconds)
    Gets the real elapsed time from the given time in seconds.
    static double
    hoursToDays(double hours)
    Converts a value in hours to days.
    static double
    hoursToMinutes(double hours)
    Converts a value in hours to minutes.
    static double
    hoursToSeconds(double hours)
    Converts a value in hours to seconds.
    static double
    microToMilli(double micro)
    Converts any value in micro (μ) to milli (m) scale, such as microseconds to milliseconds.
    static double
    microToSeconds(double micro)
    Converts a value in microseconds (μ) to seconds.
    static double
    millisecsToMinutes(long milli)
    Converts a value in milliseconds to minutes.
    static double
    minutesToSeconds(double minutes)
    Converts a value in minutes to seconds.
    static double
    monthsToSeconds(double months)
    Converts a value in months to an approximated number of seconds, since it considers every month has 30 days.
    static double
    secondsToDays(double seconds)
    Converts a value in seconds to days.
    static double
    secondsToHours(double seconds)
    Converts a value in seconds to hours.
    static double
    secondsToMinutes(double seconds)
    Converts a value in seconds to minutes.
    static String
    secondsToStr(double seconds)
    Converts a given amount of seconds to the most suitable unit, i.e., the highest unit that results in the lower converted value.
    static double
    validateTime(String fieldName, double value)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • secondsToStr

      public static String secondsToStr(double seconds)
      Converts a given amount of seconds to the most suitable unit, i.e., the highest unit that results in the lower converted value. For instance, if a value such as 80400 seconds is given, it will be converted to 1 day. It is not converted to hour, for instance, because it will return 24 (hours): a value which is higher than 1 (day).
      Parameters:
      seconds - the number of seconds to convert to a suitable unit
      Returns:
      a String containing the converted value followed by the name of the converted unit (e.g. "2.6 days")
    • currentTimeSecs

      public static double currentTimeSecs()
      Gets the computer actual time in seconds.
      Returns:
    • elapsedSeconds

      public static double elapsedSeconds(double startTimeSeconds)
      Gets the real elapsed time from the given time in seconds. This is not a simulated time, but the actual time some operation you want to measure took to finish.
      Parameters:
      startTimeSeconds - the start time in seconds you may get from currentTimeSecs()
      Returns:
      the real elapsed time in seconds
    • elapsedSeconds

      public static long elapsedSeconds(long startTimeSeconds)
      Gets the real elapsed time from the given time in seconds. This is not a simulated time, but the actual time some operation you want to measure took to finish.
      Parameters:
      startTimeSeconds - the start time in seconds you may get from currentTimeSecs()
      Returns:
      the real elapsed time in seconds
    • microToMilli

      public static double microToMilli(double micro)
      Converts any value in micro (μ) to milli (m) scale, such as microseconds to milliseconds.

      The existing TimeUnit and Duration classes don't provide the double precision required here.

      Parameters:
      micro - the value in micro (μ) scale
      Returns:
      the value in milli (m) scale
    • microToSeconds

      public static double microToSeconds(double micro)
      Converts a value in microseconds (μ) to seconds.

      The existing TimeUnit and Duration classes don't provide the double precision required here.

      Parameters:
      micro - the value in microseconds (μ)
      Returns:
      the value in seconds
    • minutesToSeconds

      public static double minutesToSeconds(double minutes)
      Converts a value in minutes to seconds.

      The existing TimeUnit and Duration classes don't provide the double precision required here.

      Parameters:
      minutes - the value in minutes
      Returns:
      the value in seconds
    • millisecsToMinutes

      public static double millisecsToMinutes(long milli)
      Converts a value in milliseconds to minutes.

      The existing TimeUnit and Duration classes don't provide the double precision required here.

      Parameters:
      milli - the value in milliseconds
      Returns:
      the value in minutes
    • secondsToMinutes

      public static double secondsToMinutes(double seconds)
      Converts a value in seconds to minutes.

      The existing TimeUnit and Duration classes don't provide the double precision required here.

      Parameters:
      seconds - the value in seconds
      Returns:
      the value in minutes
    • secondsToHours

      public static double secondsToHours(double seconds)
      Converts a value in seconds to hours.

      The existing TimeUnit and Duration classes don't provide the double precision required here.

      Parameters:
      seconds - the value in seconds
      Returns:
      the value in hours
    • secondsToDays

      public static double secondsToDays(double seconds)
      Converts a value in seconds to days.

      The existing TimeUnit and Duration classes don't provide the double precision required here.

      Parameters:
      seconds - the value in seconds
      Returns:
      the value in days
    • hoursToDays

      public static double hoursToDays(double hours)
      Converts a value in hours to days.

      The existing TimeUnit and Duration classes don't provide the double precision required here.

      Parameters:
      hours - the value in hours
      Returns:
      the value in days
    • hoursToMinutes

      public static double hoursToMinutes(double hours)
      Converts a value in hours to minutes.

      The existing TimeUnit and Duration classes don't provide the double precision required here.

      Parameters:
      hours - the value in hours
      Returns:
      the value in minutes
    • hoursToSeconds

      public static double hoursToSeconds(double hours)
      Converts a value in hours to seconds.

      The existing TimeUnit and Duration classes don't provide the double precision required here.

      Parameters:
      hours - the value in hours
      Returns:
      the value in seconds
    • daysToSeconds

      public static double daysToSeconds(double days)
      Converts a value in days to seconds.

      The existing TimeUnit and Duration classes don't provide the double precision required here.

      Parameters:
      days - the value in days
      Returns:
      the value in seconds
    • daysToHours

      public static double daysToHours(double days)
      Converts a value in days to hours.

      The existing TimeUnit and Duration classes don't provide the double precision required here.

      Parameters:
      days - the value in days
      Returns:
      the value in hours
    • monthsToSeconds

      public static double monthsToSeconds(double months)
      Converts a value in months to an approximated number of seconds, since it considers every month has 30 days.

      The existing TimeUnit, Duration and Period classes don't provide the double precision required here.

      Parameters:
      months - the value in months
      Returns:
      the value in seconds
    • validateTime

      public static double validateTime(String fieldName, double value)