Python将日期字符串转换为时间戳

Python将日期字符串转换为时间戳,python,python-2.7,date,Python,Python 2.7,Date,我需要将字符串类型Wed,2016年5月18日11:21:35 GMT转换为Python中的时间戳。我正在使用: datetime.datetime.strptime(string, format) 但是我不想指定日期类型的格式 但是我不想指定日期类型的格式 然后,让解析器明白: >>> from dateutil.parser import parse >>> parse("Wed, 18 May 2016 11:21:35 GMT") datetime.

我需要将字符串类型Wed,2016年5月18日11:21:35 GMT转换为Python中的时间戳。我正在使用:

datetime.datetime.strptime(string, format)
但是我不想指定日期类型的格式

但是我不想指定日期类型的格式

然后,让解析器明白:

>>> from dateutil.parser import parse
>>> parse("Wed, 18 May 2016 11:21:35 GMT")
datetime.datetime(2016, 5, 18, 11, 21, 35, tzinfo=tzutc())
但是我不想指定日期类型的格式

然后,让解析器明白:

>>> from dateutil.parser import parse
>>> parse("Wed, 18 May 2016 11:21:35 GMT")
datetime.datetime(2016, 5, 18, 11, 21, 35, tzinfo=tzutc())

要解析电子邮件、http和其他internet协议中使用的rfc 822时间字符串,可以使用
email
stdlib模块:

#!/usr/bin/env python
from email.utils import parsedate_tz, mktime_tz

timestamp = mktime_tz(parsedate_tz("Wed, 18 May 2016 11:21:35 GMT"))

请参阅。

要解析电子邮件、http和其他internet协议中使用的rfc 822时间字符串,您可以使用
电子邮件
stdlib模块:

#!/usr/bin/env python
from email.utils import parsedate_tz, mktime_tz

timestamp = mktime_tz(parsedate_tz("Wed, 18 May 2016 11:21:35 GMT"))