duration 

Displays the given millisecond value in human-readable time. For example, the value of 604800000 (7 days) is displayed as 7 Days.
A month is treated as 30 days and a year as 365 days.
Parameters
| Name | Type | Required | Default |
|---|---|---|---|
milliseconds | number | ● | – |
| The duration to format, in milliseconds. | |||
options![]() named | DurationOptions | – | – |
| Formatting options. See the table below. | |||

named parameters are passed as named parameters in Dart and keyword arguments in Python.
DurationOptions| Name | Type | Required | Default |
|---|---|---|---|
useShortString | boolean | – | false |
Use short unit labels: Years→Y, Months→Mo, Days→D, Hours→H, Minutes→M, Seconds→S, Milliseconds→ms. (Months uses Mo so it does not clash with Minutes (M).) | |||
useSpace | boolean | – | true |
Put a space between the value and its unit (e.g. 1Days → 1 Days). | |||
withZeroValue | boolean | – | false |
Include zero-valued units below the largest unit (e.g. 1 Day 0 Hours 0 Minutes 0 Seconds). | |||
separator | string | – | ' ' |
String placed between units (e.g. - gives 1 Hour-10 Minutes). | |||
withMilliSeconds | boolean | – | false |
Include the millisecond unit. When false, values below one second are omitted. | |||
maxUnitCount | number | – | – |
| Maximum number of units to display, counted from the largest. Omit for unlimited. | |||
unit | string | – | – |
Express the whole duration with a single unit, allowing fractions (e.g. Hour → 48 Hours, 0.5 Hours). One of Year, Month, Day, Hour, Minute, Second, Millisecond. | |||
Returns
string
Examples
javascript
duration(1234567890); // Returns '14 Days 6 Hours 56 Minutes 7 Seconds'
duration(1234567890, {
withMilliSeconds: true
}); // Returns '14 Days 6 Hours 56 Minutes 7 Seconds 890 Milliseconds'
duration(34560000000); // Returns '1 Year 1 Month 5 Days'
duration(34560000000, {
maxUnitCount: 2
}); // Returns '1 Year 1 Month'
duration(172800000, {
unit: 'Hour'
}); // Returns '48 Hours'
duration(1800000, {
unit: 'Hour'
}); // Returns '0.5 Hours'
duration(604800000, {
useSpace: false
}); // Returns '7Days'dart
duration(1234567890); // Returns '14 Days 6 Hours 56 Minutes 7 Seconds'
duration(1234567890, withMilliSeconds: true); // Returns '14 Days 6 Hours 56 Minutes 7 Seconds 890 Milliseconds'
duration(34560000000); // Returns '1 Year 1 Month 5 Days'
duration(34560000000, maxUnitCount: 2); // Returns '1 Year 1 Month'
duration(172800000, unit: 'Hour'); // Returns '48 Hours'
duration(1800000, unit: 'Hour'); // Returns '0.5 Hours'
duration(604800000, useSpace: false); // Returns '7Days'python
duration(1234567890) # Returns '14 Days 6 Hours 56 Minutes 7 Seconds'
duration(1234567890, {
'withMilliSeconds': True
}) # Returns '14 Days 6 Hours 56 Minutes 7 Seconds 890 Milliseconds'
duration(34560000000) # Returns '1 Year 1 Month 5 Days'
duration(34560000000, {
'maxUnitCount': 2
}) # Returns '1 Year 1 Month'
duration(172800000, {
'unit': 'Hour'
}) # Returns '48 Hours'
duration(1800000, {
'unit': 'Hour'
}) # Returns '0.5 Hours'
duration(604800000, {
'useSpace': False
}) # Returns '7Days'