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!

3
  • 1
    Please post a Minimal, complete, verifiable example, just a few lines to illustrate your problem. Commented Nov 21, 2017 at 1: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. Commented Nov 21, 2017 at 1:48
  • I'll check back in the morning to see whether you've posted (not commented) a MCVE (not narration). Commented Nov 21, 2017 at 1:55

1 Answer 1

1

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.