to_j_duration
to_j_duration
converts a time duration value to a Java Duration
, which is a unit of time in terms of clock time (counting days, hours, minutes, seconds, and nanoseconds).
info
In query strings, users should choose the built-in function parseDuration
instead of to_j_duration
. For more information, see:
Syntax
to_duration(dt: Union[None, Duration, int, str, datetime.timedelta, numpy.timedelta64, pandas.Timedelta]) -> Duration
Parameters
Parameter | Type | Description |
---|---|---|
dt | Union[None, Duration, int, str, datetime.timedelta, numpy.timedelta64, pandas.Timedelta] | A date-time value to convert to a Java Duration. Strings can be formatted according to the ISO-8601 standard, which is Strings can also be formatted as |
Returns
Returns a Duration
representation of the duration string.
Examples
from deephaven.time import to_j_duration
from datetime import timedelta
import numpy as np
import pandas as pd
delta = timedelta(days=40, seconds=33, microseconds=21)
timedelta_np = np.timedelta64(1, "M")
timedelta_pd = pd.Timedelta(1, "d")
duration_from_string = to_j_duration("PT1H5M-5S")
duration_from_int = to_j_duration(500_000_000_000)
duration_from_timedelta = to_j_duration(delta)
duration_from_np_timedelta = to_j_duration(timedelta_np)
duration_from_pd_timedelta = to_j_duration(timedelta_pd)
print(duration_from_string)
print(duration_from_int)
print(duration_from_timedelta)
print(duration_from_np_timedelta)
print(duration_from_pd_timedelta)