Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

Python Pandas - ส่งคืนการประทับเวลาใหม่ที่แสดงวันและเวลา UTC


หากต้องการส่งคืน Timestamp ใหม่ที่แสดงวันและเวลา 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

# 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