Created
December 21, 2011 21:49
-
-
Save sente/1507868 to your computer and use it in GitHub Desktop.
an example snippet for wrestling with python's datetime formatting to create RFC 2822 compatible times
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from email.utils import formatdate | |
from datetime import datetime, timedelta, tzinfo | |
""" | |
prints the current time and time from three hours ago in RFC 2822 (email) format | |
stu@sente ~ $ python rfc2822.py | |
Wed, 21 Dec 2011 16:45:46 -0500 | |
Wed, 21 Dec 2011 13:45:46 -0500 | |
""" | |
now = datetime.now() | |
delta = timedelta(hours=-3) | |
newdate = now + delta | |
print formatdate(float(now.strftime("%s")),tzinfo()) | |
print formatdate(float(newdate.strftime("%s")),tzinfo()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment