Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format Django DateField as ISO format

Tags:

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?

like image 308
rein Avatar asked Mar 22 '10 15:03

rein


People also ask

What is the format of Django Datefield?

Python django format date dd/mm/yyyy And, because the format is dd/mm/yyyy, we must use a slash to separate the date, month and year. To separate the day from the month and the month from the year in a date notation we use DateSeparator.

What is Django default datetime format?

django default date to be in format %d-%m-%Y.


1 Answers

New in Django 1.2, there is a template tag that will output what you wish:

{{ value|date:"c"}} 

From the Django template documentation:

c | ISO 8601 Format | 2008-01-02T10:30:00.000123

Technically, this closer to W3-DTF, but close enough

like image 197
Edgar Avatar answered Sep 21 '22 18:09

Edgar