Python Pandas - 返回代表 UTC 日期和时间的新时间戳

要返回表示 UTC 日期和时间的新时间戳,请使用该方法。首先,导入所需的库 -timestamp.utcnow()

import pandas as pd

创建时间戳

timestamp = pd.Timestamp('2021-10-16T15:12:34.261811624', tz='UTC')

带有 UTC 日期和时间的新时间戳

timestamp.utcnow()

示例

以下是代码

import pandas as pd

# 创建时间戳
timestamp = pd.Timestamp('2021-10-16T15:12:34.261811624', tz='UTC')

# 显示时间戳
print("Timestamp...\n", timestamp)

# 带有 UTC 日期和时间的新时间戳
print("\nUTC day and time...\n", timestamp.utcnow())
输出结果

这将产生以下代码

Timestamp...
 2021-10-16 15:12:34.261811624+00:00

UTC day and time...
 2021-10-03 07:56:08.901294+00:00

猜你喜欢