描述
Pythom時間法mktime()是 localtime() 的反函數。它的參數是 struct_time 或完整的 9 元組,它返回一個浮點數,以與 time() 兼容。
如果輸入值不能表示為有效時間,則將引發 OverflowError 或 ValueError。
用法
以下是語法mktime()方法≫
time.mktime(t)
參數
t─ 這是 struct_time 或完整的 9 元組。
返回值
此方法返回一個浮點數,以與 time() 兼容。
示例
下麵的例子展示了 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
相關用法
- Python time ctime()用法及代碼示例
- Python time localtime()用法及代碼示例
- Python time sleep()用法及代碼示例
- Python time strftime()用法及代碼示例
- Python time clock()用法及代碼示例
- Python time asctime()用法及代碼示例
- Python time altzone()用法及代碼示例
- Python time tzset()用法及代碼示例
- Python time time()用法及代碼示例
- Python time replace()用法及代碼示例
- Python time gmtime()用法及代碼示例
- Python time strptime()用法及代碼示例
- Python time.monotonic()用法及代碼示例
- Python time.asctime()用法及代碼示例
- Python time.ctime()用法及代碼示例
- Python time.perf_counter()用法及代碼示例
- Python time.get_clock_info()用法及代碼示例
- Python time.gmtime()用法及代碼示例
- Python time.time()用法及代碼示例
- Python time.mktime()用法及代碼示例
注:本文由純淨天空篩選整理自 Python time mktime() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。