Skip to main content
 首页 » 编程设计

python之在 Epoch-Python 中转换日期时间

2024年09月07日6Renyi-Fan

我想将 datetime 转换为纪元。

例如,我有这种格式的datetime:2018-02-14T22:15:00.232029+01:00。

如何将其转换为纪元?由于我的日期时间格式,当我尝试在 python 中使用 datetime 或 timestamp 时,我遇到了很多错误。有什么想法吗?

请您参考如下方法:

这是一种方式:

import pandas as pd 
 
base = '1970-01-01' 
x = '2018-02-14T22:15:00.232029+01:00' 
 
(pd.to_datetime(x) - pd.to_datetime(base)).total_seconds() 
 
# 1518642900.232029