How to display “This many months ago” in Django using Humanize?

后端 未结 3 1303
我在风中等你
我在风中等你 2021-01-04 08:18

I have this variable:

{{ video.pub_date }}

which outputs:

May 16, 2011, 2:03 p.m.

How can I get it to sho

3条回答
  •  清酒与你
    2021-01-04 08:35

    {{ video.pub_date|timesince }} ago
    

    From the docs at timesince

    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, and comment_date is a date instance for 08:00 on 1 June 2006, then {{ blog_date|timesince:comment_date }} would return "8 hours".

    Comparing offset-naive and offset-aware datetimes will return an empty string.

    Minutes is the smallest unit used, and "0 minutes" will be returned for any date that is in the future relative to the comparison point.

提交回复
热议问题