【发布时间】:2015-08-11 14:28:59
【问题描述】:
我正在尝试更改我的一种 django 表单中的 DateTime 格式。
我希望它接受的格式是: 日 月 年 小时_分钟_秒 时区 2015 年 8 月 11 日 12:00:00 GMT -> %d %b %Y %H:%M:%S %Z
我一直在做一些测试,但我无法找到正确的方法。
我在 settings.py 文件中禁用了 L10N,因此我可以使用 %b 月份格式。
这是我的 forms.py 文件内容
from django import forms
from django.forms import DateTimeField
from web.apps.customer.models import Reported_VPN_User
class Customer_settings_vpn_Form(forms.ModelForm):
event_date = DateTimeField(widget=forms.widgets.DateTimeInput(format="%d %b %Y %H:%M:%S %Z"))
class Meta:
model = Reported_VPN_User
fields = '__all__'
当我尝试以所需格式输入日期时,表格不允许我继续。
我一直在检查 DATETIME_INPUT_FORMAT (https://docs.djangoproject.com/en/1.8/ref/settings/#std:setting-DATETIME_FORMAT) 并没有看到我在寻找什么,但检查 python 日期文档 (https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior) 我发现它应该是可能的。
如何修改日期时间格式,使其按要求工作?
ps:我不是 django 专家。
【问题讨论】:
标签: django datetime django-forms