RFC 1123 Date Representation in Python?

前端 未结 5 1331
南笙
南笙 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条回答
  •  天命终不由人
    2020-12-07 12:46

    You can set LC_TIME to force stftime() to use a specific locale:

    >>> locale.setlocale(locale.LC_TIME, 'en_US')
    'en_US'
    >>> datetime.datetime.now().strftime(locale.nl_langinfo(locale.D_T_FMT))
    'Wed 22 Oct 2008 06:05:39 AM '
    

提交回复
热议问题