描述
Python time mktime() 函數執行與gmtime(), localtime()相反的操作,它接收struct_time對象作為參數,傳回用秒數來表示時間的浮點數。
如果輸入的值不是一個合法的時間,将觸發 OverflowError 或 ValueError。
文法
mktime()方法文法:
time.mktime(t)
參數
- t -- 結構化的時間或者完整的9位元組元素。
傳回值
傳回用秒數來表示時間的浮點數。
執行個體
以下執行個體展示了 mktime() 函數的使用方法:
#!/usr/bin/python
import time
t = (2009, 2, 17, 17, 3, 38, 1, 48, 0)
secs = time.mktime( t )
print "time.mktime(t) : %f" % secs
print "asctime(localtime(secs)): %s" % time.asctime(time.localtime(secs))
以上執行個體輸出結果為:
time.mktime(t) : 1234915418.000000
asctime(localtime(secs)): Tue Feb 17 17:03:38 2009