I am trying to automate getting the local timezone offset but am having trouble. I've tried:
print time.timezone/3600
This gets the (currently wrong) offset as it doesn't automatically adjust for Daylight Savings Time and non-DST.
I've also tried:
now_utc = pytz.utc.localize(datetime.datetime.now())
now_mst = now_utc.astimezone(pytz.timezone('US/Mountain'))
This gets the correct offset value, but I'd like to set 'US/Mountain' part automatically so I don't have to manually input anything to get the offset.
Is there a way to get the correct offset that automatically adjusts with DST & non-DST?
I will be running this script on multiple servers in different geographies and I want to get the tz offset automatically if I can.