Get the Olson TZ name for the local timezone?

前端 未结 11 1300
孤街浪徒
孤街浪徒 2020-11-30 03:19

How do I get the Olson timezone name (such as Australia/Sydney) corresponding to the value given by C\'s localtime call?

This is the value overridden vi

11条回答
  •  执笔经年
    2020-11-30 03:30

    This JavaScript project attempts to solve the same issue in the browser client-side. It works by playing "twenty questions" with the locale, asking for the UTC offset of certain past times (to test for summer time boundaries, etc.) and using those results to deduce what the local time zone must be. I am not aware of any equivalent Python package unfortunately, so if someone wanted to use this solution it would have to be ported to Python.

    While this formula will require updating every time (at worst) the TZ database is updated, a combination of this algorithm and the solution proposed by Anurag Uniyal (keeping only possibilities returned by both methods) sounds to me like the surest way to compute the effective local timezone. As long as there is some difference between the UTC offset of at least one local time in any two time zones, such a system can correctly choose between them.

提交回复
热议问题