Changing Elixir DateTime Precision
DateTime.truncate(datetime, precision)
Calling this function on a DateTime allows you to change the level of precision from microsecond, :millisecond, or :second.
now = DateTime.utc_now()
# => ~U[2023-10-09 17:52:05.305420Z]
DateTime.truncate(now, :second)
# => ~U[2023-10-09 17:52:39Z]
Tweet