รับวันที่และเวลาปัจจุบันจากวัตถุ Timestamp ใช้ timestamp.today() วิธีการ
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import pandas as pd import datetime
สร้างการประทับเวลาใน Pandas
timestamp = pd.Timestamp(datetime.datetime(2021, 10, 10))
แสดงการประทับเวลา
print("Timestamp: ", timestamp) รับวันที่และเวลาปัจจุบัน
res = timestamp.today()
ตัวอย่าง
ต่อไปนี้เป็นรหัส
import pandas as pd
import datetime
# set the timestamp in Pandas
timestamp = pd.Timestamp(datetime.datetime(2021, 10, 10))
# display the Timestamp
print("Timestamp: ", timestamp)
# display the day from given timestamp
print("Day Name:", timestamp.day_name())
# getting the current date and time
res = timestamp.today()
# display the current date and time
print("\nToday's Date and time...\n", res)
# display the current day
print("Today's Day:", res.day_name()) ผลลัพธ์
ซึ่งจะได้รหัสดังต่อไปนี้
Timestamp: 2021-10-10 00:00:00 Day Name: Sunday Today's Date and time... 2021-10-03 13:22:28.891506 Today's Day: Sunday