Time in Python is sometimes represented using the struct_time data structure in  the time module or simply as a tuple made of 9 elements i.e  (year, month, day, hour, minute, second, weekday,  day_of_year, dst). The struct_time class simply provides a more structured way of  representing the 9 components of time.

ExampleEdit & Run

example of a struct_time object

import time

st_obj = time.localtime()

print(st_obj)
Output:
time.struct_time(tm_year=2024, tm_mon=12, tm_mday=3, tm_hour=5, tm_min=6, tm_sec=15, tm_wday=1, tm_yday=338, tm_isdst=0)[Finished in 0.010964896995574236s]

The work of the mktime() function.

The mktime() function in the time module converts a struct_time object or a tuple containing the 9 element of time to a Unix timestamp (seconds since the epoch).  

Syntax:
mktime(t)
t struct_time object, or a tuple with time components. 
Parameters:

The function returns a floating point value representing the number seconds since the epoch of the input date.

ExampleEdit & Run
import time

st_obj = time.localtime()

print(time.mktime(st_obj))
Output:
1733191575.0[Finished in 0.010909382021054626s]

In the above example, we used the time.localtime() function without any argument to get a struct_time object representing the current local time, then we used the mktime() function to convert the struct_time object to the equivalent  timestamp.

ExampleEdit & Run

With the time components in a tuple

import time

t = (2021, 9, 17, 17, 3, 38, 1, 48, 0)

print(time.mktime(t))
Output:
1631887418.0[Finished in 0.010689873015508056s]