Python Pandas - 返回表示 UTC 日期和時間的 Timestamp


要返回一個表示 UTC 日期和時間的新 Timestamp,請使用 timestamp.utcnow() 方法。首先,匯入所需的庫 −

import pandas as pd

建立一個 Timestamp

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

帶有 UTC 日期和時間的新 Timestamp

timestamp.utcnow()

範例

以下為程式碼

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())

輸出

將生成以下程式碼

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

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

更新於: 13-Oct-2021

236 次瀏覽

開啟你的 職業 生涯

完成該課程獲得認證

開始
廣告