# Duration

## class Duration(seconds, nanoseconds=0)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object "(in Python v3.15)")

A nonnegative duration with nanosecond precision.

Construct a duration from seconds and an additional nanosecond count.

Parameters:
:   - **seconds** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)"))

      Whole nonnegative seconds.
    - **nanoseconds** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)"))

      Additional nonnegative nanoseconds. Defaults to zero.

Returns:
:   *Duration* – Their sum, within the native duration range.

Examples

```
>>> Duration(1, 500_000_000).as_millis()
1500
```

Methods

| [`as_millis`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.types.Duration.md#instro.opcua.types.Duration.as_millis "instro.opcua.types.Duration.as_millis") | Return total whole milliseconds, truncating any smaller unit. |
| --- | --- |
| [`as_nanos`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.types.Duration.md#instro.opcua.types.Duration.as_nanos "instro.opcua.types.Duration.as_nanos") | Return total whole nanoseconds, truncating any smaller unit. |
| [`as_secs`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.types.Duration.md#instro.opcua.types.Duration.as_secs "instro.opcua.types.Duration.as_secs") | Return total whole seconds, truncating any smaller unit. |
| [`from_millis`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.types.Duration.md#instro.opcua.types.Duration.from_millis "instro.opcua.types.Duration.from_millis") | Construct a duration from a nonnegative integer count of milliseconds. |
| [`from_nanos`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.types.Duration.md#instro.opcua.types.Duration.from_nanos "instro.opcua.types.Duration.from_nanos") | Construct a duration from a nonnegative integer count of nanoseconds. |
| [`from_secs`](https://dev.nominal.io/instro/ref/protocols/instro.opcua.types.Duration.md#instro.opcua.types.Duration.from_secs "instro.opcua.types.Duration.from_secs") | Construct a duration from a nonnegative integer count of seconds. |

### as_millis()

Return total whole milliseconds, truncating any smaller unit.

### as_nanos()

Return total whole nanoseconds, truncating any smaller unit.

### as_secs()

Return total whole seconds, truncating any smaller unit.

### static from_millis(milliseconds)

Construct a duration from a nonnegative integer count of milliseconds.

### static from_nanos(nanoseconds)

Construct a duration from a nonnegative integer count of nanoseconds.

### static from_secs(seconds)

Construct a duration from a nonnegative integer count of seconds.
