A span of time, such as 27 days, 4 hours, 12 minutes, and 3 seconds.
A span of time, such as 27 days, 4 hours, 12 minutes, and 3 seconds.
A Duration
represents a difference from one point in time to another. The
duration may be "negative" if the difference is from a later time to an
earlier.
To create a new Duration object, use this class's single constructor giving the appropriate arguments:
Duration fastestMarathon = new Duration(hours:2, minutes:3, seconds:2);
The Duration is the sum of all individual parts. This means that individual parts can be larger than the next-bigger unit. For example, minutes can be greater than 59.
assert(fastestMarathon.inMinutes == 123);
All individual parts are allowed to be negative.
Use one of the properties, such as inDays, to retrieve the integer value of the Duration in the specified time unit. Note that the returned value is rounded down. For example,
Duration aLongWeekend = new Duration(hours:88);
assert(aLongWeekend.inDays == 3);
This class provides a collection of arithmetic and comparison operators, plus a set of constants useful for converting time units.
See DateTime to represent a point in time. See Stopwatch to measure time-spans.