首页 文章资讯内容详情

Python Pandas - 获取 UTC 偏移时间

2026-06-03 1 花语

要获取UTC偏移时间,请使用.首先,导入所需的库-timestamp.utcoffset()

import pandas as pd

创建时间戳

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

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

timestamp.utcnow()

获取UTC偏移时间

timestamp.utcoffset()

示例

以下是代码

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()) #获取UTC偏移时间 print("\nUTC offset time...\n", timestamp.utcoffset())输出结果

这将产生以下代码

Timestamp... 2021-10-16 15:12:34.261811624+00:00 UTC day and time... 2021-10-03 07:56:44.685816+00:00 UTC offset time... 0:00:00