招生電話:0816-8119777
新聞詳情

python教程——time mktime()方法

發(fā)表時(shí)間:2023-06-27 15:50

描述

Python time mktime() 函數(shù)執(zhí)行與gmtime(), localtime()相反的操作,它接收struct_time對(duì)象作為參數(shù),返回用秒數(shù)來表示時(shí)間的浮點(diǎn)數(shù)。


如果輸入的值不是一個(gè)合法的時(shí)間,將觸發(fā) OverflowError 或 ValueError。


語法

mktime()方法語法:


time.mktime(t)

參數(shù)

t -- 結(jié)構(gòu)化的時(shí)間或者完整的9位元組元素。

返回值

返回用秒數(shù)來表示時(shí)間的浮點(diǎn)數(shù)。


實(shí)例

以下實(shí)例展示了 mktime() 函數(shù)的使用方法:


#!/usr/bin/python3

import time


t = (2016, 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)))

以上實(shí)例輸出結(jié)果為:


time.mktime(t) : 1455699818.000000

asctime(localtime(secs)): Wed Feb 17 17:03:38 2016


辦公室/傳真:0816-8119666
招生辦:0816- 8119777
地址:四川省綿陽市園藝山教育園區(qū)
郵箱:mzsyxxzsb@sina.com
官方服務(wù)號(hào)
官方訂閱號(hào)
官方視頻號(hào)
官方抖音號(hào)
官方微博號(hào)
北京英才苑
四川省電化教育館
綿陽教育體育館
綿陽招生考試網(wǎng)
友情鏈接: