[New-bugs-announce] [issue7584] datetime.rfcformat() for Date and Time on the Internet
anatoly techtonik
report at bugs.python.org
Sun Dec 27 20:18:08 CET 2009
New submission from anatoly techtonik <techtonik at gmail.com>:
RFC 3339 defines a standard for Date and Time on the Internet.
http://www.ietf.org/rfc/rfc3339.txt Given that Python is increasingly
popular on the Internet is should include convenience function to
generate RFC 3339 timestamps in standard library.
It is impossible to generate RFC 3339 timestamps (that are also valid
ISO 8601 timestamps) with datetime.strftime() alone, so the following
code should be used:
import datetime
def rfcformat(dt):
""" Output datetime in RFC 3339 format that is also valid ISO 8601
timestamp representation"""
if dt.tzinfo is None:
suffix = "-00:00"
else:
suffix = dt.strftime("%z")
suffix = suffix[:-2] + ":" + suffix[-2:]
return dt.strftime("%Y-%m-%dT%H:%M:%S") + suffix
----------
components: Library (Lib)
messages: 96917
nosy: techtonik
severity: normal
status: open
title: datetime.rfcformat() for Date and Time on the Internet
versions: Python 2.7, Python 3.1, Python 3.2
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7584>
_______________________________________
More information about the New-bugs-announce
mailing list