0

I am trying to get the client timezone information string. For example: America/New_York,Africa/Cairo..etc Now I can only get client_timezone_offset. I convert it to datetime first, and tried to get timezone information. But I can only get the string like "UTC+08:00". Is there any way that I can get timezone string like "America/New_York" ?

This is my sample code, I can only get the string like "UTC+08:00"

dt = datetime.fromtimestamp(
            float(time.time()),
            timezone(timedelta(seconds=self.current_request.client_timezone_offset)),
        )
        tz = timezone(timedelta(seconds=self.current_request.client_timezone_offset))
        timezone_string = (
            "America/New_York" if tz.tzname(dt) is None else str(tz.tzname(dt))
        )
avseq
  • 23
  • 4
  • Does this answer your question? [How can I get a human-readable timezone name in Python?](https://stackoverflow.com/questions/3489183/how-can-i-get-a-human-readable-timezone-name-in-python) – KingsDev Sep 02 '22 at 04:14
  • Note: you cannot. Time offset has not enough information. Many timezones may have the same time offset. And they may not be equivalent (one with summer time, one without, or with different period, or in other hemisphere. I would also not recommend to do it: it gives often false information (also time offset). Good for formatting user data (but careful! I rented a car before a summer time change, and the system got starting time wrong, which caused a lot of extra works on many people). – Giacomo Catenazzi Sep 02 '22 at 06:35

0 Answers0