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
0 comments
Copy link
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>
copied to clipboard
Comments (0)
Sign in with GitHub to join the discussion