A span of time, such as 27 days, 4 hours, 12 minutes, and 3 seconds.
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.
Durations are context independent. For example, a duration of 2 days is always 48 hours, even when it is added to a
DateTime just when the time zone is about to do a daylight-savings switch. (See DateTime.add).
Despite the same name, a
Duration object does not implement "Durations" as specified by ISO 8601. In particular, a duration object does not keep track of the individually provided members (such as "days" or "hours"), but only uses these arguments to compute the length of the corresponding time interval.
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);
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.
Durationis negative. [...]
Durationrepresenting the absolute value of this
other, returning zero if the values are equal. [...]
factorand returns the result as a new Duration object. [...]
otherand returns the sum as a new Duration object.
otherfrom this Duration and returns the difference as a new Duration object.
trueif the value of this Duration is less than the value of
trueif the value of this Duration is less than or equal to the value of
trueif this Duration has the same value as
trueif the value of this Duration is greater than the value of
trueif the value of this Duration is greater than or equal to the value of
quotientand returns the truncated result as a new Duration object. [...]
microsecondsPerHour * hoursPerDay
microsecondsPerMinute * minutesPerHour
microsecondsPerSecond * secondsPerMinute
microsecondsPerMillisecond * millisecondsPerSecond
millisecondsPerHour * hoursPerDay
millisecondsPerMinute * minutesPerHour
millisecondsPerSecond * secondsPerMinute
minutesPerHour * hoursPerDay
secondsPerHour * hoursPerDay
secondsPerMinute * minutesPerHour
const Duration(seconds: 0)
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.