我正在try 以小时为单位转换两个时区之间的偏移量.
hour_offset
变量的类型为SET,我希望能够将该值用于其他计算,因此在下面的示例中,计算应为9小时.
<class 'set'>
{8.0}
print(1 + hour_offset)
~~^~~~~~~~~~~~~
TypeError: unsupported operand type(s) for +: 'int' and 'set'
from datetime import datetime
from zoneinfo import ZoneInfo
dt = datetime.now()
tz0, tz1 = "America/Los_Angeles", "Europe/London"
utcoff0, utcoff1 = dt.astimezone(ZoneInfo(tz0)).utcoffset(), dt.astimezone(ZoneInfo(tz1)).utcoffset()
print(f"hours offset between {tz0} -> {tz1} timezones: {(utcoff1-utcoff0).total_seconds()/3600}")
hour_offset = ({(utcoff1-utcoff0).total_seconds()/3600})
print(type(hour_offset))
print(hour_offset)
print(1 + hour_offset)