Score:0

Converting Unix Timestamp to Time Ago Format in twig

cn flag

I'm working on a project where I need to convert a Unix timestamp to a "time ago" format (e.g., "2 hours ago," "3 days ago," etc.) using Twig. I've tried using the {{ created|date('M Y, D') }} function, but it only provides a regular date and time format.

Can someone please guide me on how to modify the code to achieve the desired "time ago" format? I want to display the elapsed time since the timestamp in a more human-readable format.

If there are any specific functions, libraries, or code examples available in Twig that can help with this conversion, I would greatly appreciate the guidance.

Thank you in advance for your assistance!

Ziftman avatar
cn flag
In Twig, you can utilize the date filter for formatting date objects. However, it doesn't directly provide a "time ago" format. This functionality is typically achieved through a custom Twig filter or extension.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.