Epoch (epoch v1.1.0) View Source

Conversion between Elixir native DateTime.t/0 and epoch formats.

Link to this section Summary

Functions

Accepts a DateTime and converts it to epoch with microseconds.

Returns the current time in epoch format.

Returns the current time in epoch format with millisecond resolution.

Converts an epoch with microseconds to a DateTime.t/0

Link to this section Functions

Specs

cast(DateTime.t()) :: String.t()

Accepts a DateTime and converts it to epoch with microseconds.

Examples

iex> cast(~U[2020-12-20 02:26:29.000800Z])
"1608431189.000800"

iex> cast(~U[2020-12-20 02:26:29Z])
"1608431189.000000"

Specs

now() :: integer()

Returns the current time in epoch format.

Specs

now(:microsecond) :: String.t()

Returns the current time in epoch format with millisecond resolution.

Specs

to_datetime(String.t() | integer()) :: DateTime.t()

Converts an epoch with microseconds to a DateTime.t/0

Examples

iex> to_datetime("1608431189.000800")
~U[2020-12-20 02:26:29.000800Z]

iex> to_datetime("1608431189")
~U[2020-12-20 02:26:29Z]

iex> to_datetime(1_608_431_189)
~U[2020-12-20 02:26:29Z]