Bor*_*rja 6 django datetime django-forms
我试图在我的一个django表单中更改DateTime格式.
我希望它接受的格式是:day month year hour_minute_seconds timezone 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的专家.
不要用format.请input_formats改用,它接受格式列表:
event_date = DateTimeField(input_formats=["%d %b %Y %H:%M:%S %Z"])
| 归档时间: | 
 | 
| 查看次数: | 15207 次 | 
| 最近记录: |