简体   繁体   English

带有模板过滤器的 django 中的日期时间将显示不同的值

[英]Datetime in django with template filter will show different value

I'm using Django template filters to format a datetime instance, but it looks like its value differs from raw date in the datebase.我正在使用 Django 模板过滤器来格式化日期时间实例,但它的值看起来与日期库中的原始日期不同。

I used datetime.now() in Python to create the instance.我在Python使用datetime.now()来创建实例。

{{ modeltest.date }}

will show将会呈现

"Jan. 3, 2019, 5:27 a.m."

on the page, but在页面上,但

{{ modeltest.date | date:"Y-m-d H:m:s" }}

displays显示

"2019-01-03 05:01:19"

Note the difference of the minutes displayed ( 5:27 vs 05:01 )请注意显示的分钟数的差异( 5:2705:01

I'm getting a little confused here.我在这里有点困惑。 Does anyone know this?有人知道吗?

You mixed up the date filters .您混淆了日期过滤器 You used the month twice (lowercase m ) instead of using minutes (lowercase i ).您使用了两次月份(小写m )而不是使用分钟(小写i )。

You are seeing "2019-01-03 05:01:19" (with the minutes as 01 instead of 27 ) because it actually show the month (January is the first month, so 01 ).您看到的是"2019-01-03 05:01:19" (分钟数为01而不是27 ),因为它实际上显示了月份(一月是第一个月,所以01 )。


You can change this你可以改变这个

date:"Y-m-d H:m:s"

to

date:"Y-m-d H:i:s"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM