Python Pandar - 获取 UTC 时间偏移
要获取 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
# creating a timestamp
timestamp = pd.Timestamp('2021-10-16T15:12:34.261811624', tz='UTC')
# display the Timestamp
print("Timestamp...\n", timestamp)
# new timestamp with UTC day and time
print("\nUTC day and time...\n", timestamp.utcnow())
# Get the UTC offset time
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP