import numpy as np
import dascore as dc
# Convert an iso 8601 string to datetime64
= dc.to_datetime64('2017-09-17T12:11:01.23212')
dt_1
# Convert a time stamp (seconds from 1970) to datetime64
= dc.to_datetime64(631152000.0)
dt_2
# Convert an array of time stamps to datetime64
= np.random.uniform(1704400000, 1704900000)
timestamp_array = dc.to_datetime64(timestamp_array) dt_array
to_datetime64
to_datetime64(
obj: int | float | str | numpy.datetime64 | pandas._libs.tslibs.timestamps.Timestamp | numpy.ndarray[int, float, str, datetime64, Timestamp, ndarray] ,
)
Convert an object to a datetime64.
This function accepts a wide range of inputs and returns something of the same shape, but converted to numpy’s datetime64 representation.
Parameters
Parameter | Description |
---|---|
obj |
An object to convert to a datetime64. If a string is passed, it should conform to ISO 8601. Floats and integers are interpreted as seconds from Jan 1st, 1970. Arrays and Series of floats or strings are also supported. |