Reputation: 65
I have a datetime that represents an event creation time and I need to show how much time has passed since then.
Examples: “right now”, “2 days ago”, “3 months from now”.
I know of PrettyTime for Java, but I need something for Django.
Thanks!
Upvotes: 1
Views: 584
Reputation: 14501
Not sure if it is exactly what you are looking for, but Django does have a built in template filter that achieves something similar: timesince
Formats a date as the time since that date (e.g., "4 days, 6 hours").
Takes an optional argument that is a variable containing the date to use as the comparison point (without the argument, the comparison point is now). For example, if
blog_date
is a date instance representing midnight on 1 June 2006, andcomment_date is a date instance for 08:00 on 1 June 2006, then
{{ blog_date|timesince:comment_date }}` would return "8 hours".
Upvotes: 2