Timestamps calculated at different times are the same for python3.6

I want to calculate the timestamps at different times. On the linux server, I call the package time that comes with python, but the timestamps of 2:00 a.m. on April 15, 1990 and 3:00 a.m. on April 15, 1990 are the same Yes, I want to ask if it is the problem of the python package itself, thank you

Python 3.6.9 (default, Jan 26 2021, 15:33:00)

[GCC 8.4.0] on linux

Type “help”, “copyright”, “credits” or “license” for more information.

$import time

$time.mktime(time.strptime(str(‘1990-04-15 02:00:00’), ‘%Y-%m-%d %H:%M:%S’))

$640116000.0

$time.mktime(time.strptime(str(‘1990-04-15 03:00:00’), ‘%Y-%m-%d %H:%M:%S’))

$640116000.0

Welcome to our Forum.

I can’t replicate your results:

Python 3.6.9 (default, Mar 15 2022, 13:55:28) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.mktime(time.strptime(str('1990-04-15 02:00:00'), '%Y-%m-%d %H:%M:%S'))
640141200.0
>>> time.mktime(time.strptime(str('1990-04-15 03:00:00'), '%Y-%m-%d %H:%M:%S'))
640144800.0
>>> 

This seems likely to be related to your time zone; was that a “spring forward” time in your area? Can you reproduce the result if you start Python with TZ=Etc/UTC python3.6?

1 Like

In your timezone, there was no 2:00:00. The second before (640115999) was 1:59:59 standard time. The second after (640116000) was 3:00:00 summer time.

When you ask it to figure out what epoch time maps to 2:00:00, it picks the same as 3:00:00 since that’s the only thing that makes sense.

1 Like