Lấy ngày và giờ hiện tại từ đối tượng Dấu thời gian, sử dụng timestamp.today () phương pháp.
Đầu tiên, hãy nhập các thư viện được yêu cầu -
import pandas as pd import datetime
Tạo dấu thời gian trong Pandas
timestamp = pd.Timestamp(datetime.datetime(2021, 10, 10))
Hiển thị Dấu thời gian
print("Timestamp: ", timestamp) Lấy ngày và giờ hiện tại
res = timestamp.today()
Ví dụ
Sau đây là mã
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()) Đầu ra
Điều này sẽ tạo ra mã sau
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