Today I Learned

hashrocket A Hashrocket project

Elixir DateTime now in seconds

I just found out that since elixir 1.15.0 we can call DateTime utc now and get that response truncated in seconds already:

iex> DateTime.utc_now(:second)
~U[2025-06-03 13:27:44Z]

and this has the same effect of what I used to do until now:

iex> DateTime.utc_now() |> DateTime.truncate(:second)
~U[2025-06-03 13:27:45Z]
See More #elixir TILs
Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.