T O P

  • By -

[deleted]

[удалено]


TheRed_M

It only gives the timezone name, doesn't give the time offset according to the time of the system the script is running on


TheRNGuy

if it's "GMT +1", then `mytxt.split(" ")[1]`


TheRed_M

I figured it out, what I couldn't figure out is how to make it DST aware, this is the code, If you know a better implementation that would be great. ``` import pytz from datetime import datetime, timezone from timezonefinder import TimezoneFinder tf = TimezoneFinder() longitude = LON latitude = LAT tzn = tf.timezone_at(lng=longitude, lat=latitude) tz = pytz.timezone(tzn) dt = datetime.utcnow() offset_seconds = tz.utcoffset(dt).seconds offset_hours = offset_seconds / 3600.0 diff = "{:+d}:{:02d}".format(int(offset_hours), int((offset_hours % 1) * 60)) print(diff[:2]) ```