我知道如何以相反的方式做到这一点...它将是:
>>> dt.rfc822()
'Sun, 09 Mar 1997 13:45:00 -0500'
Run Code Online (Sandbox Code Playgroud)
Joh*_*ooy 30
In [1]: import rfc822 # This only works for python 2 series
In [2]: rfc822.parsedate_tz('Sun, 09 Mar 1997 13:45:00 -0500')
Out[2]: (1997, 3, 9, 13, 45, 0, 0, 1, 0, -18000)
Run Code Online (Sandbox Code Playgroud)
在python3中,parsedate_tz已移至email.utils
>>> import email.utils # this works on Python2.5 and up
>>> email.utils.parsedate_tz('Sun, 09 Mar 1997 13:45:00 -0500')
(1997, 3, 9, 13, 45, 0, 0, 1, -1, -18000)
Run Code Online (Sandbox Code Playgroud)
从 python 3.3 开始,有email.utils.parsedate_to_datetime(date)
>>> from email.utils import parsedate_to_datetime
>>> datestr = 'Sun, 09 Mar 1997 13:45:00 -0500'
>>> parsedate_to_datetime(datestr)
datetime.datetime(1997, 3, 9, 13, 45, tzinfo=datetime.timezone(datetime.timedelta(-1, 68400)))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8310 次 |
| 最近记录: |