1

In Python 3.5, when I convert POSIX origin 1970-01-01 to timestamp (in seconds) instead of 0 I get the following result:

import datetime as dt
t = dt.datetime(1970,1,1)
t.timestamp()
-10800.0

Expected 0 is produced by:

t = dt.datetime(1970,1,1,3)
t.timestamp()
0.0

Both results are quite unexpected to me. What could be a reason for such a behaviour?

Sergey Bushmanov
  • 23,310
  • 7
  • 53
  • 72

1 Answers1

2

According to the docs: Naive datetime instances are assumed to represent local time

You get a negative count so I guess you happen to be at UTC-3 (10800 / 60 / 60) (and you get a 0 when adding 3 hours)

Make a timezone aware date and you should be back at 0.

mementum
  • 3,153
  • 13
  • 20