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

วิธีแปลง Integer เป็น Date Object ใน Python

ใช้ fromtimestamp จาก datetime Module แปลง UNIX Timestamp เป็น DateTime Object

ตัวอย่าง

import datetime

timestamp = datetime.datetime.fromtimestamp(1500000000)
print(timestamp.strftime('%Y-%m-%d %H:%M:%S'))

ผลลัพธ์

2017-07-14 08:10:00

UNIX Timestamp = วินาทีตั้งแต่ Epoch (1970-01-01 00:00:00 UTC)