如何在12小时内显示Django时间,而不是24小时制 [英] How to display Django time in 12 hour time instead of military 24
问题描述
当我使用以下内容时
created = models.DateTimeField('date published')
它显示这样的时间
23:12:06
而不是
11:12:06
我希望它显示时间是12小时而不是24小时。同样,当我按now小部件时,时间也要晚4分钟。 cd
I want it to display time in 12 hr not 24. Also when I press the now widget the time is 4 minutes behind. Any help would be appreciatecd
推荐答案
Django具有内置的日期格式,例如:
Django have built-in date formatting, like this:
创建= DateTimeField(input_formats = ['%Y-%m-%d%I:%M%p'])
这是有关此字母如何工作的完整备忘单:
http://blog.tkbe.org/archive/date-filter-cheat-sheet/
因此,要实现12小时格式,请使用 h'或'g'取决于您是否要使用前导零
So, to implement 12hour format, use 'h' or 'g' depending on if you want to have leading zeros or not
在Django文档中也提到过:
https://docs.djangoproject.com/en/dev/ref/forms/fields/#datetimefield
It is also mentioned in django doc: https://docs.djangoproject.com/en/dev/ref/forms/fields/#datetimefield
这是开发版本,我不知道您使用的是哪个版本
This is for dev version, i dont know which one you are using
时间晚4分钟
time is 4 minutes behind
您的TIME_ZONE设置正确吗?
Is your TIME_ZONE in settings correct ?
这篇关于如何在12小时内显示Django时间,而不是24小时制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!