为什么datetime.datetime返回的结果与pd.to_datetime不同

时间:2019-10-31 03:05:53

标签: python-3.x pandas datetime

我想知道为什么datetime.datetime.timestamp返回的结果与pd.to_datetime.timestamp不同

这里是一个例子:

from datetime import datetime
import pandas as pd

now = datetime.now()
print(now.timestamp())
print(pd.to_datetime(now).timestamp())

# 1572490362.553197
# 1572472362.553197

1 个答案:

答案 0 :(得分:0)

Bharath M是正确的:

import datetime 
import pandas as pd

now = datetime.datetime.now(datetime.timezone.utc)
print(now.timestamp())
print(pd.to_datetime(now, utc=True).timestamp())

# 1572493959.718966
# 1572493959.718966