1

I have a Timezone in the following format: country/city (for example: America/Sao_Paulo). I want to change with python my system's timezone (Win7) with it, is it possible to do it with Pytz and Datetime, or at all ?

Thank you !

jfs
  • 399,953
  • 195
  • 994
  • 1,670
user180894
  • 79
  • 1
  • 4
  • On Unix, `os.environ['TZ'] = 'America/Sao_Paulo'; time.tzset()` changes time/datetime local time for your process – jfs Mar 27 '14 at 11:22

1 Answers1

2

In general, no. There is not a direct Python way to do this.

It could be done, but you would have to jump through a lot of hoops:

  • Use CLDR data to translate the IANA zone to a Windows zone id.
    • Ex. America/Sao_Paulo => E. South America Standard Time
    • (See the Databases section of the timezone tag wiki for more details.)
  • Get the appropriate Win32 security permissions.
  • Call into the Win32 SetTimeZone API

Caling Win32 functions from Python is done via ctypes.

Here's a walkthrough of which Win32 permissions and calls to make, although it's in C# in this sample. You will need to translate for Python.

Sounds like a lot of work to me. Not sure why you would want to do this.

Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575