RFC 1123 Date Representation in Python?

前端 未结 5 1350
南笙
南笙 2020-12-07 12:28

Is there a fairly easy way to convert a datetime object into an RFC 1123 (HTTP/1.1) date/time string, i.e. a string with the format

Sun, 06 Nov 1994 08:49:37         


        
5条回答
  •  旧时难觅i
    2020-12-07 12:42

    You can use the formatdate() function from the Python standard email module:

    from email.utils import formatdate
    print formatdate(timeval=None, localtime=False, usegmt=True)
    

    Gives the current time in the desired format:

    Wed, 22 Oct 2008 10:32:33 GMT
    

    In fact, this function does it "by hand" without using strftime()

提交回复
热议问题