Formatting RFC 822 date
Matthew Dixon Cowles
matt at mondoinfo.com
Wed Apr 4 14:43:00 EDT 2001
On 3 Apr 2001 18:25:45 GMT, brey at ductape.net <brey at ductape.net> wrote:
>Is there a module that I'm missing that will take a time tuple and output the
>proper RFC 822 date string?
Ed,
I'll append what I do in Swallow. I think it's right.
Regards,
Matt
def getRfc822Date():
# Can't use the strings from the time module since they
# vary by locale and RFC822 (amended by RFC1123) requires
# English.
dayNames=("Mon","Tue","Wed","Thu","Fri","Sat","Sun")
monthNames=("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug", \
"Sep","Oct","Nov","Dec")
timeTuple=time.localtime(time.time())
timeStr=dayNames[timeTuple[6]]+", "+str(timeTuple[2])+" "+ \
monthNames[timeTuple[1]]+" "+str(timeTuple[0])+" "
timeStr=timeStr+time.strftime("%H:%M:%S ",timeTuple)
if timeTuple[8]<>0:
zoneSecs=time.altzone
else:
zoneSecs=time.timezone
zoneAbsSecs=abs(zoneSecs)
zoneMins=zoneSecs/60
zoneHours=int(zoneMins/60) # Actually already integer division
zoneLeftoverMins=zoneMins-zoneHours*60
if zoneSecs>0:
timeStr=timeStr+"-"
timeStr=timeStr+"%02i%02i " % (zoneHours,zoneLeftoverMins)
timeStr=timeStr+"("+time.tzname[timeTuple[8]]+")"
return timeStr
More information about the Python-list
mailing list