3

Python 2.7.8, I call:

import datetime
print datetime.datetime.fromtimestamp(10)

But there are different results depending on operating system:

  • 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 any way to unify returned value, so that result is same on different OSes?

user1781713
  • 177
  • 7
  • If you only want comparable timestamps, [time.time()](https://docs.python.org/2/library/time.html#time.time) gives you seconds since the Epoch. See [this question](http://stackoverflow.com/questions/14186179/in-python-is-epoch-time-returned-by-time-always-measured-from-jan-1-1970) for details. – maxy Dec 07 '14 at 17:08

2 Answers2

2

It's likely the two operating systems had different timezone settings.

The python standard library does not make available an implementation of timezone (as written in the python's documentation for tzinfo). Anyway you should use the third-party (pure-python) pytz module like in the following code.

from datetime import datetime
from pytz import timezone

tz = timezone('America/St_Johns')
datetime.fromtimestamp(10, tz)
Giova
  • 1,879
  • 1
  • 19
  • 27
  • 1
    The same happens here as the OP, with Python 3.5, and both Ubuntu and Windows 10 set to the London time zone. – reupen Apr 16 '16 at 18:13
0

Do you have any timezone differences?

https://docs.python.org/2/library/datetime.html

Have a look at the tzinfo in the datetime library docs, I wonder if that is different

joeButler
  • 1,643
  • 1
  • 20
  • 41