尝试将进程默认时区设置为 Asia/Shanghai。
()
| 22 | |
| 23 | |
| 24 | def apply_process_timezone() -> None: |
| 25 | """ |
| 26 | 尝试将进程默认时区设置为 Asia/Shanghai。 |
| 27 | """ |
| 28 | try: |
| 29 | os.environ.setdefault("TZ", "Asia/Shanghai") |
| 30 | if hasattr(time, "tzset"): |
| 31 | time.tzset() |
| 32 | except Exception: |
| 33 | # 不阻断主流程 |
| 34 | pass |
| 35 | |
| 36 | |
| 37 | def now_shanghai() -> datetime: |