⊗pyPmTmSTEG 195 of 208 menu

Getting epoch format from struct_time in Python

To get the epoch seconds from the struct_time object again, you can use the mktime method of the time module.

Let's get a struct_time object using the gmtime method:

now = time.time() st_time = time.gmtime(now)

Then we transform struct_time using the mktime method:

res = time.mktime(st_time) print(res) # the number of seconds
byenru