Skip to main content
 首页 » 编程设计

python之在 Python 中将 http 请求时间转换为 unix 时间戳

2025年05月04日13dudu

亲们, 我如何将以下字符串转换为 unix 纪元时间戳?

Thu, 03 Oct 2013 14:55:44 GMT 

我可以通过以下方式获取本地 http 时间戳:

In [53]: now = datetime.now() 
 
In [54]: stamp = mktime(now.timetuple()) 
 
In [55]: print format_date_time(stamp) 
Thu, 03 Oct 2013 16:24:59 GMT 

我如何将生成的 unix 时间戳转换回上述格式?

谢谢!

请您参考如下方法:

>>> import time 
>>> int(time.time()) 
1380817337 
>>>