We can use time.tzname get a local timezone name, but that name is not compatible with pytz.timezone.
In fact, the name returned by time.tzname is ambiguous. This method returns ('CST', 'CST') in my system, but ‘CST’ can indicate four timezones:
- Central Time Zone (North America) – observed in North America’s Central Time Zone
- China Standard Time
- Chungyuan Standard Time – the term “Chungyuan Standard Time” is now rarely in use in Taiwan
- Australian Central Standard Time (ACST)
A very simple method to solve this question:
Update: @MartijnPieters said ‘This won’t work with DST / summertime.’ So how about this version?