Jun-23-2023, 09:27 PM
(This post was last modified: Jun-23-2023, 09:27 PM by deanhystad.)
As I said, the timestamps are UTC (I said GMT earlier, but they are the same) and when displayed will be corrected for the timezone you are in. A file changed in Kuala Lampur will have a timestamp 15 hours older when viewed from a computer in Kuala Lampur than the same file viewed from Seattle. You can verify this by changing the timezone for your computer. Instantly the timestamps will agree.
I think the problem may be that you are being naive. Read the section about Aware vs Naive.
https://docs.python.org/3/library/datetime.html
You might also find this interesting.
https://howchoo.com/g/ywi5m2vkodk/workin...-in-python
Here's an example of using "aware" datetime objects.
I think the problem may be that you are being naive. Read the section about Aware vs Naive.
https://docs.python.org/3/library/datetime.html
You might also find this interesting.
https://howchoo.com/g/ywi5m2vkodk/workin...-in-python
Here's an example of using "aware" datetime objects.
import pytz import os x = os.path.getctime("input.txt") koala_lampur = datetime.fromtimestamp(x, tz=pytz.timezone('Asia/Kuala_Lumpur')) seattle = datetime.fromtimestamp(x, tz=pytz.timezone('US/Pacific')) here = datetime.fromtimestamp(x) print("Koala Lampur", koala_lampur) print("Seattle", seattle) print("US Central", here) print(koala_lampur == seattle, koala_lampur == here, seattle == here)
Output:Koala Lampur 2023-02-14 10:59:15.117121+08:00
Seattle 2023-02-13 18:59:15.117121-08:00
US Central 2023-02-13 20:59:15.117121
True False False
Even though Seattle and Koala Lampur datetime strings are 15 hours apart, Python returns True when asked if they are equal. The naive "here" datetime object displays a correct US/Central time, but is not appropriate for comparing against datetime objects from different time zones.