Skip to main content
 首页 » 编程设计

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

2025年05月04日16www_RR

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

datetime.datetime.strptime(string, format) 

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

请您参考如下方法:

But I don't want to specify the format for the date type.

然后,让 dateutil解析器计算出来:

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