1

There is a web series starting on 2017-01-11 19:00 Warsaw time. I want to make a list of time zones for major cities to help people figure out when to tune in. How can I tell Python that the date variable is related to the time in Warsaw?

import datetime
from pytz import timezone
from pytz import common_timezones

# warsaw time
s = '2017-01-11 19:00:00.801000'
format = '%Y-%m-%d %H:%M:%S.%f'
date = datetime.datetime.strptime(s, format)

fmt = "%Y-%m-%d %H:%M:%S %Z%z"
warsaw_time = date
print(warsaw_time.strftime(fmt))

for zone in common_timezones:
  print( zone + str(warsaw_time.astimezone(timezone(zone))) )
  • Possible duplicate of [How to get system timezone setting and pass it to pytz.timezone?](https://stackoverflow.com/questions/13218506/how-to-get-system-timezone-setting-and-pass-it-to-pytz-timezone) – tripleee Dec 28 '17 at 10:21

1 Answers1

0

If I understand correctly, you are trying to set the date to Warsaw's local time (CET). Which you can do like this:

>>> warsaw = pytz.timezone("CET")
>>> dt = datetime.datetime(2017, 1, 11, 19, 0, 0, 0, warsaw)
>>> dt
datetime.datetime(2017, 1, 11, 19, 0, tzinfo=<DstTzInfo 'CET' CET+1:00:00 STD>)
ybl
  • 1,510
  • 10
  • 16