1

I don't understand why in the datetime constructor I can set the tzinfo but printing the date results in different offsets.

This is taken by my local machine in Italy. I have a script on Heroku, I do not know where it resides every time it reboots, so that has to synchronize to Rome time, I cannot manually set the datetime.timedelta

import datetime
import pytz


tz = pytz.timezone("Europe/Rome")

now = datetime.datetime.now(tz=tz)
start = datetime.datetime(now.year, now.month, now.day, hour=17, tzinfo=tz)
stop_ = datetime.datetime(now.year, now.month, now.day, hour=23, minute=59, second=59, tzinfo=tz)

print(now)
print(start)
print(stop_)


> 2021-06-30 11:14:50.639378+02:00
> 2021-06-30 17:00:00+00:50
> 2021-06-30 23:59:59+00:50

I don't exactely know what +00:50 should represent. I just noticed that a routine was getting executed one hour later than expected (it should run at 5pm Rome time, but it runs at 6pm). During winter, it always ran at the expected time.

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
davide m.
  • 452
  • 4
  • 19

0 Answers0