0

I'm new in python windows winapi.

How to get an location time from winapi using python so the result time is like (UTC-08:00) Pacific Time (US & Canada)

I have tried using win32api.GetTimeZoneInformation() but the result just an number (1, (480, u'Pacific Standard Time', <PyTime:11/1/2000 2:00:00 AM>, 0, u'Pacific Daylight Time', <PyTime:3/2/2000 2:00:00 AM>, -60))

sorry for noob & bad question.

  • I like the answer from @pp_ that doesn't use any third-party packages, however I also notice that the actual [Python 2.7 documentation](https://docs.python.org/2/library/datetime.html#tzinfo-objects) recommends using the third-party `pytz` package. – Kyle Pittman Feb 10 '16 at 15:33
  • I want get result like this [question](http://stackoverflow.com/questions/12112419/getting-windows-time-zone-information-c-mfc?rq=1) in python, in there using c++ I don't know about c++. – Edi Santoso Feb 10 '16 at 15:43

1 Answers1

4

Check out the Python time module:

import time

utc_offset = time.strftime('%z')
tz_name = time.tzname[0]

print('(UTC{0}) {1}'.format(utc_offset, tz_name))
pp_
  • 3,435
  • 4
  • 19
  • 27
  • `tzname` may be corrupted mojibake depending on your system locale, current preferred thread language, and current thread locale when `time` is first imported. With Japanese as the preferred language in the default C locale, the value of `tzname` in the UTC timezone is `'\x8b\xa6\x92\xe8\x90¢\x8aE\x8e\x9e'`, which is the ANSI (CP932) encoding mistakenly cast as a Unicode string. I have to first set the thread `LC_CTYPE` locale to Japanese to get the correct string, `'協定世界時'`. It would be better to use the Windows Unicode API directly via ctypes instead. – Eryk Sun Feb 10 '16 at 16:15