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

การได้เวลาปัจจุบัน (Getting current time) ใน Python

เพื่อแปลง instant เวลาจาก seconds since the epoch floating-point value เป็น time-tuple ให้ส่งค่า floating-point ไปยังฟังก์ชัน (เช่น localtime) ที่คืนค่า time-tuple พร้อมรายการทั้งเก้าที่ถูกต้อง

ตัวอย่าง

#!/usr/bin/python
import time
localtime = time.localtime(time.time())
print "Local current time :", localtime

ผลลัพธ์ (Output)

นี่จะผลิตผลลัพธ์ดังนี้ ซึ่งอาจจัดรูปแบบในรูปแบบอื่นที่นำเสนอได้:

Local current time : time.struct_time(tm_year=2013, tm_mon=7, tm_mday=17, tm_hour=21, tm_min=26, tm_sec=3, tm_wday=2, tm_yday=198, tm_isdst=0)