Python 2.7.8: Different fromtimestamp values ββfor Windows and Linux
Python 2.7.8, I am calling:
import datetime
print datetime.datetime.fromtimestamp(10)
But depending on the operating system, there are different results:
- 1970-01-01 01:00:10 - Linux
- 1970-01-01 00:00:10 - Windows
So there is one hour shift. Is this a known issue? Is there a way to unify the return value so that the result is the same across different OSes?
+3
source to share
2 answers
The two operating systems likely had different time zone settings.
The python standard library does not provide a timezone implementation (as written in the python documentation for tzinfo ). In any case, you should use the third party (pure-python) pytz module as in the following code.
from datetime import datetime
from pytz import timezone
tz = timezone('America/St_Johns')
datetime.fromtimestamp(10, tz)
+2
source to share
Do you have any time zone differences?
https://docs.python.org/2/library/datetime.html
Have a look at tzinfo in the datetime library docs, I wonder if this is different from
0
source to share