gpt4 book ai didi

Django 日期时间任务友好格式

转载 作者:行者123 更新时间:2023-12-02 07:59:08 25 4
gpt4 key购买 nike

如何格式化 django 日期时间,以便它以任务友好的格式生成结果

23 sec remaining
2 hour 14 minutes remaining
4 days

最佳答案

您会发现 timeuntil过滤很有用。

{{ my_datetime|timeuntil:target_date }}

上面的代码片段将返回到达 target_date 之前的剩余时间。

timeuntil

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

Takes an optional argument that is a variable containing the date to use as the comparison point (instead of now). If from_date contains 22 June 2006, then {{
conference_date|timeuntil:from_date }}
will return "1 week".

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 past relative to the comparison point.

关于Django 日期时间任务友好格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3540143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com