Django中的“x天前”模板过滤器? [英] "x Days ago' template filter in Django?

查看:84
本文介绍了Django中的“x天前”模板过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个将datetime实例转换为x Days或x years y months格式的过滤器(如SO)。建议?我可以俯瞰某些非常明显的东西吗?

I'm looking for a filter that turns a datetime instance into 'x Days' or 'x years y months' format (as on SO). Suggestions? Am I overlooking something very obvious?

推荐答案

看看 timesince 模板过滤器。它是内置的。

Have a look at the timesince template filter. It's builtin.

以下内容返回现在和 comment_date 之间的人性化差异(例如 8小时'):

The following returns a humanized diff between now and comment_date (e.g. '8 hours'):

{{ comment_date|timesince }}

以下内容返回 question_date 之间的人性化差异comment_date

{{ comment_date|timesince:question_date }}

这篇关于Django中的“x天前”模板过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆