主题
Duration
一段时间跨度,例如 27 天、4 小时、12 分钟和 3 秒。
Duration 表示两个时间点之间的差值。如果差值是从较晚的时间点指向较早的时间点,则该时长可能为"负"。
属性
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
microseconds | int | 0 | The number of microseconds in the duration. |
milliseconds | int | 0 | The number of milliseconds in the duration. |
seconds | int | 0 | The number of seconds in the duration. |
minutes | int | 0 | The number of minutes in the duration. |
hours | int | 0 | The number of hours in the duration. |
days | int | 0 | The number of days in the duration. |
只读属性
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
in_microseconds | int | — | Returns total duration in microseconds. |
in_milliseconds | int | — | Returns total duration in milliseconds. |
in_seconds | int | — | Returns total duration in seconds. |
in_minutes | int | — | Returns total duration in minutes. |
in_hours | int | — | Returns total duration in hours. |
in_days | int | — | Returns total duration in days. |
is_negative | bool | — | Returns True if duration is negative. |
方法
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
from_unit | 'Duration' | — | Creates a Duration from individual time units. |
abs | 'Duration' | — | Returns absolute (non-negative) Duration. |
copy | 'Duration' | — | Returns a copy of this Duration instance with the given fields replaced with the new values. |