开发者

Date format for django's SelectDateWidget

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 fi开发者_如何学编程x 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?


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'


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


The correct way to do this is with spaces rather than forward slashes i.e.

DATE_FORMAT = "%d %m %Y"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜