We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Showing relative time in HEEX using Timex
almirsarajcic
Created
Here’s how to show when a record was created relative to the current time, e.g. “3 minutes ago”.
Add the Timex dependency ({:timex, "~> 3.7"}
) to your mix.exs
file, then use it:
def created_at(assigns) do
~H"""
<time datetime={Timex.format!(@created_at, "{ISO:Extended:Z}")}>
<%= Timex.format!(@created_at, "{relative}", :relative) %>
</time>
"""
end
and the result will look like this:
<time datetime="2024-12-18T11:01:00Z">4 minutes ago</time>
Copy link
copied to clipboard