Issue
I'm using Django to serve up some XML. Part of the requirements is that my dates are formatted as follows: 1969-12-31T18:33:28-06:00
How can I output a DateField in Django in that format?
Solution
If you look under date in the Django documentation you'll see that a variety of formats for the date are supported. Basically in a template you need:
{{ value|date:"some format string" }}
where the format string can be one of the ones defined under date on the page above or one of the custom ones defined under the now function (which includes ISO 8601 format) which is also on the page linked to above. I'm assuming that when you output to xml you do so in a similar way to a template for a normal web page.
Update (August 2014)
As indicated in another answer by Edgar R, as of version 1.2 onwards you can now use a built in switch to output the date in ISO 8601 format using format string: c
Answered By - Amos
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.