Django datetime - user friendly format

How would you format django datetime, so it gives the results in a user-friendly format.

23 sec remaining
2 hour 14 minutes remaining
4 days
+3
source share
1 answer

You will find a filter timeuntil.

{{ my_datetime|timeuntil:target_date }}

The above snippet will return the remaining time until it is reached target_date.

timeuntil

Similarly timesince, except that it measures from time to time until a date or a date. For example, if today is June 1, 2006 and conference_date is an instance of the date June 29, 2006, then it {{ conference_date|timeuntil }}will return "4 weeks".

, , ( ). from_date 22 2006 , {{ conference_date|timeuntil:from_date }} "1 ".

- .

- , "0 " , .

+3

Source: https://habr.com/ru/post/1760948/


All Articles