For the following code, I expect the seconds_input and seconds_output, to be the same. But I get an hour difference:
import time
seconds_input = 1571875186
date_struct1 = time.gmtime(seconds_input)
tm_str = time.strftime("%Y-%m-%d %H:%M:%S", date_struct1)
date_struct2 = time.strptime(tm_str, '%Y-%m-%d %H:%M:%S')
seconds_output = time.mktime(date_struct2)
print(seconds_input - seconds_output)
print(date_struct1, date_struct2)
I assume it could be due to tm_isdst=-1
in the date_struct2
, but I'm not sure how to set it to 0
.
I have tried the date_struct2.tm_isdst = 0
, but got the following error:
AttributeError: readonly attribute
Update:
if the seconds_input corresponds to the date in the future, then the seconds_input and seconds_output would be the same.
For example if seconds_input = 1673084786.