Unix Timestamp in Elixir

Use `DateTime` and `System.os_time` from the standard library.

Common Operations

Get current Unix timestamp (seconds)

ts = System.os_time(:second)
# 1706745600

Convert Unix timestamp to DateTime

{:ok, dt} = DateTime.from_unix(1706745600)
# ~U[2024-01-31 22:40:00Z]

Format as ISO 8601

DateTime.utc_now() |> DateTime.to_iso8601()
# '2024-01-31T22:40:00.123456Z'

Other Languages

Need the full converter? Open the Timestamp Converter →