0

with python's datetime package, I'm seeing a ~8min time difference between datetime.now().timestamp() and datetime(year, month, day, hour, minute, second, [tz]).timestamp(), when I put now's time in the latter formula. With or without the tz, which is timezone, the 8min difference stays there. Anyone can explain where it went wrong? Thanks!

Alison Z
  • 85
  • 1
  • 8
  • 1
    Please post a [Minimal, complete, verifiable example](http://stackoverflow.com/help/mcve), just a few lines to illustrate your problem. – Prune Nov 21 '17 at 01:34
  • let's say now is nov 20, 17:44, pacific time. with datetime.now().timestamp(), I got a number 1511228640. This is equal to the actual utc time. But when I used datetime(2017, 11, 20, 17, 44, 0, 0, [pacific_time]), I got 1511228220, which 420 seconds, i.e. 7 minutes different from the actual utc. And the pacific_time tz variable's existence doesn't make a difference. – Alison Z Nov 21 '17 at 01:48
  • I'll check back in the morning to see whether you've posted (not commented) a MCVE (not narration). – Prune Nov 21 '17 at 01:55

1 Answers1

1

You can (and should) use tzinfo.localize() instead.

https://stackoverflow.com/a/6411149/1114412

georgechen
  • 71
  • 1