0

I am using python 3.6

I converted midnight of "US/Pacific" timezone to unix timestamp.

When I convert the timestamp back to "US/Pacific" local time, I see its 7 minutes before the midnight.

Can anyone shade light on what is happening?

>>> (
    datetime(2021, 5, 5, 0, 0)
    .replace(tzinfo=pytz.timezone("US/Pacific"))
    .timestamp()
)

>>> 1620201180.0

>>> datetime.utcfromtimestamp(1620201180.0)
>>> datetime.datetime(2021, 5, 5, 7, 53)

>>> datetime.fromtimestamp(1620201180.0, tz=pytz.timezone("US/Pacific"))
>>> datetime.datetime(2021, 5, 5, 0, 53, tzinfo=<DstTzInfo 'US/Pacific' PDT-1 day, 17:00:00 DST>)

FYI I am located at "Asia/Kathmandu" timezone.

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
wrufesh
  • 1,379
  • 3
  • 18
  • 36
  • 1
    Does this answer your question? [Weird timezone issue with pytz](https://stackoverflow.com/questions/11473721/weird-timezone-issue-with-pytz) – FObersteiner May 19 '22 at 10:16
  • Also related: [python: utcfromtimestamp vs fromtimestamp](https://stackoverflow.com/q/62286398/10197418) – FObersteiner May 19 '22 at 10:16
  • Basically: with pytz, **use localize**, not replace. And [Stop using utcnow and utcfromtimestamp](https://blog.ganssle.io/articles/2019/11/utcnow.html), it's pretty confusing ;-) – FObersteiner May 19 '22 at 10:18

0 Answers0