问题
SelectDateWidget is very convenient but it normally seems to return dates in the format "%Y-%m-%d". It doesn't take a format parameter and doesn't have much documentation. Anyone run into this or have an idea how to work around it to get the output of the date into another format? There is this ticket, #6231 saying that there's a fix to have it use a DATE_FORMAT setting from settings.py (though I don't see why it can't just be given a format parameter also). There's a patch in the ticket from 2 months ago to implement this, so it seems I would have to get the latest dev version of django to use it, unless there is a way I can apply just this patch to my django install?
回答1:
DATE_FORMAT works with SelectDateWidget but you have to use format strings without percents (as used in: now template tag) like this:
DATE_FORMAT = 'j N Y'
回答2:
Have you tried this setting yet ? According to the docs, it seems DATE_FORMAT=
has been a valid setting since version 1.0. Are you using a pre-1.0 version of django?
http://docs.djangoproject.com/en/1.0/ref/settings/#date-format
回答3:
The correct way to do this is with spaces rather than forward slashes i.e.
DATE_FORMAT = "%d %m %Y"
来源:https://stackoverflow.com/questions/1554783/date-format-for-djangos-selectdatewidget