The mktime method of the time module
The mktime method of the time module converts a string with a date and time into seconds. In the method parameter, we specify the time structure struct_time or a tuple of 9 elements with the mandatory dst flag, which displays local time.
Syntax
import time
time.mktime(time structure or tuple)
Example
Let's convert a date and time string to seconds:
import time
struct_time = time.strptime('10/10/2020 10:15', '%d/%m/%Y %H:%M')
res = time.mktime(struct_time)
print(res)
The result of the executed code:
1602314100.0
See also
-
method
timeof moduletime,
which returns the time in seconds since the epoch -
method
ctimeof moduletime,
which converts seconds to a datetime string -
method
localtimeof moduletime,
which converts seconds to local time -
method
gmtimeof moduletime,
which converts seconds to UTC format -
method
sleepof moduletime,
which stops the operation from running for the specified number of seconds