Package 

Class Duration

  • All Implemented Interfaces:
    java.lang.Comparable

    
    public class Duration
     implements Comparable<Duration>
                        

    Replacement for Java duration class which has only been introduced in SDK 26

    • Method Summary

      Modifier and Type Method Description
      static Duration ofNanos(long nanoSeconds) Returns a new Duration object based on amount of nanoseconds.
      static Duration ofMillis(long milliSeconds) Returns a new Duration object based on amount of milliseconds.
      static Duration ofMillis(double milliSeconds) Returns a new Duration object based on amount of fractional milliseconds.
      long toNanos() Returns the amount of nanoseconds in this duration.
      int toMillis() Returns the amount of milliseconds in this duration.
      double toMillisFractional() Returns the amount of milliseconds in this duration.
      int compareTo(Duration duration) Compares 2 duration objects.
      • Methods inherited from class java.lang.Comparable

        compareTo
      • Methods inherited from class java.lang.Object

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

      • ofNanos

         static Duration ofNanos(long nanoSeconds)

        Returns a new Duration object based on amount of nanoseconds.

        Parameters:
        nanoSeconds - duration in nanoseconds.
      • ofMillis

         static Duration ofMillis(long milliSeconds)

        Returns a new Duration object based on amount of milliseconds.

        Parameters:
        milliSeconds - duration in milliseconds.
      • ofMillis

         static Duration ofMillis(double milliSeconds)

        Returns a new Duration object based on amount of fractional milliseconds.

        Parameters:
        milliSeconds - duration in milliseconds.
      • toNanos

         long toNanos()

        Returns the amount of nanoseconds in this duration.

      • toMillis

         int toMillis()

        Returns the amount of milliseconds in this duration.

      • toMillisFractional

         double toMillisFractional()

        Returns the amount of milliseconds in this duration.

      • compareTo

         int compareTo(Duration duration)

        Compares 2 duration objects.

        Parameters:
        duration - another duration to be compared.