[docs] [issue12758] time.time() returns local time instead of UTC

Antoine Pitrou report at bugs.python.org
Wed Jan 16 22:53:00 CET 2013


Antoine Pitrou added the comment:

> It makes a difference. It seems with the current behaviour, the
> "epoch" is _in the local timezone_.

No it isn't. Two different machines:

$ LANG=C date
Wed Jan 16 21:47:03 UTC 2013
$ python -c "import time; print(time.time())"
1358372827.5

$ LANG=C date
Wed Jan 16 22:47:21 CET 2013
$ python -c "import time; print(time.time())"
1358372848.2

time.time() *is* timezone-independent.

Now to your question:

> However, what I'd really prefer is a new function that returns the
> seconds since the epoch in UTC.

>>> epoch = datetime(1970, 1, 1)
>>> (datetime.utcnow() - epoch).total_seconds()
1358372978.448235
>>> time.time()
1358372980.176238

----------
nosy: +pitrou

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12758>
_______________________________________


More information about the docs mailing list