【问题标题】:django naturaltime returning the same resultdjango naturaltime 返回相同的结果
【发布时间】:2020-03-15 07:49:18
【问题描述】:
In my model i have a fields like : 

时间 = models.DateTimeField(auto_now_add=True)

In view page i am getting the value like in this format :

2020-03-15T11:07:07.089Z

I am getting the date time in this format.

{{ result.time|naturaltime }}

但它不工作它返回我来自数据库的同一日期

【问题讨论】:

  • 大家有什么建议吗???一个
  • 你的问题不清楚,你到底想做什么。添加更多详细信息,我们将为您提供帮助:3
  • @M3duZa 我的问题是我正在以这种格式获取日期:2020-03-15T11:07:07.089Z 如何在 2020 年 3 月 15 日上午 07:07 进行转换
  • 你可以试试auto_now_add,而不是auto_now

标签: python django django-admin


【解决方案1】:

您应该使用DateField 而不是DateTimeField。 喜欢 : time = models.DateField(auto_now_add=True) 这是 django 字段的链接(为了更清楚):https://docs.djangoproject.com/en/2.2/ref/models/fields/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-03
    • 2016-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多