我通常使用此代码来获取本地时区:import platformimport timeimport datetimeimport pytz#LOCAL_TIMEZONE = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo # "CEST", etc on Linux, but 'Romance Standard Time' on Windowsif "win" in platform.system().lower(): # SO:1387222 # SO:16156597 - try tzlocal.win32; MINGW64: `pip3.8.exe install tzlocal`; RPi: `sudo apt install python3-tzlocal` from tzlocal.win32 import get_localzone_name LOCAL_TIMEZONE = pytz.timezone(get_localzone_name())else: from tzlocal import get_localzone LOCAL_TIMEZONE = get_localzone()# Above results with LOCAL_TIMEZONE: Europe/Copenhagen in Linux, Europe/Paris in Windows如何获得适用于 Windows 和 Linux 的本地时区 CET 或 CEST(字母代码)?
添加回答
举报
0/150
提交
取消