tags:

views:

29

answers:

1
+1  Q: 

Rfc 1123 in python

Hi guys.

Just want to use 'datetime' or 'time' modules. I based the following code on this question:

import time

def rfc1123 (gmt):
    weekday = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][gmt.tm_wday]

    month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][gmt.tm_mon]

    return "%s, %02d %s %04d %02d:%02d:%02d GMT" % (weekday, gmt.tm_mday, month, gmt.tm_year, gmt.tm_hour, gmt.tm_min, gmt.tm_sec)

print (rfc1123 (time.gmtime ()))

Is something wrong ? I'm really worried about the DST.

Thanks.

+2  A: 

An easier way to do it :

from time import strftime, gmtime
strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())

See exemple in python python documentation

ohe