Python time mktime() Method
Description
The Python time mktime() function performs the opposite operation of gmtime() and localtime(). It takes a struct_time object as a parameter and returns a floating-point number representing the time in seconds.
If the input value is not a valid time, an OverflowError or ValueError will be raised.
Syntax
Syntax of the mktime() method:
time.mktime(t)
Parameters
- t -- A structured time or a complete 9-tuple element.
Return Value
Returns a floating-point number representing the time in seconds.
Examples
The following example demonstrates how to use the mktime() function:
Example
#!/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))
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))
The output of the above example is:
time.mktime(t) : 1234915418.000000 asctime(localtime(secs)): Tue Feb 17 17:03:38 2009Other Extensions