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
廣告