Python time mktime() method
Description
The Python time mktime() function performs the reverse operation of gmtime() and localtime(): it takes a struct_time object and returns the time as a floating-point number of seconds.
If the input value is not a valid time, OverflowError or ValueError is raised.
Syntax
mktime() method syntax:
time.mktime(t)
Parameters
- t -- a structured time or a full 9-element tuple.
Return Value
Returns the time as a floating-point number of seconds.
Example
The following example shows 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
)
"time.mktime(t) : %f"
% secs
"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 2009