Python中 time time()返回時當前時間的時間戳(1970紀元后經過的浮點秒數)
time()方法語法:
time.time()
實際案例:
# coding: UTF-8 import time print("time.time():%f" % time.time())
執行結果:

time.localtime() 返回代表當地具體時間,年、月、日、時、分、秒、周幾、一年中的第幾天、是否是夏令時等信息。
localtime()方法語法:
time.localtime([參數,時間戳浮點數])
實際案例:
# coding: UTF-8 import time print(time.localtime()) #當參數為空時默認為當前時間 a = 1529907030.229088 print(time.localtime(a)) #指定參數返回時間 #獲取單獨的年月日信息 t = time.localtime() print("當前年份:%s 當前月份:%s 當前日期:%s" % (t.tm_year,t.tm_mon,t.tm_mday))
執行結果:

time.asctime():返回已經格式化的時間字符串。 參數必須是表示時間的struct_time元組,為空時將time.localtime()作為參數
asctime()方法語法:
time.localtime()
實際案例:
# coding: UTF-8 import time print(time.asctime())
執行結果:

