Atom feed date function
Updated about 1 year ago (24 Jul 2008 at 03:17 AM)
recent activity
| In Brief | A function for converting a timezone aware datetime object into an RFC 3339 compliant date format, as used by the atom feed and sitemap updated tag.... more |
| Language | Python |
# 's
1def date_internet(date):
2 d = date.strftime('%Y-%m-%dT%H:%M:%S%z')
3 return d[:-2] + ':' + d[-2:]
A function for converting a timezone aware datetime object into an RFC 3339 compliant date format, as used by the atom feed and sitemap updated tag.
The ugliness of the code stems from the fact that the UTC offset format parameter %z returns a solid time, like -0700, but RFC 3339 requires the : between the hour and minutes, like -07:00.
If you know of a cleaner way to do this... please feel free to change it.
Add a Comment