Latest web development tutorials

Python3 time mktime () method


Python time mktime () function performs gmtime (), localtime () reverse operation, which receives struct_time object as a parameter and returns a float to represent the number of seconds of time.

If the value entered is not a valid time, it will trigger OverflowError or ValueError.


mktime () method syntax:



  • t - structured time or full nine yuan set of elements.

return value

Returns the number of seconds used to represent floating point of time.


The following example shows mktime () function to use:

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)))

The above example output is:

time.mktime(t) : 1455699818.000000
asctime(localtime(secs)): Wed Feb 17 17:03:38 2016