基於添金的win32api docs,所述方法採用以下形式的元組:
[0] INT:偏置
[1]字符串:StandardName
[2] SYSTEMTIME元組:StandardDate
[3] int:StandardBias
[4]字符串:DaylightName
[5] SYSTEMTIME元組:DaylightDate
[6] INT:DaylightBias
更關鍵的是,嘗試win32api.GetTimeZoneInformation
(docs)看什麼元組應當看起來像這樣win32api.SetTimeZoneInformation
不會抱怨。
編輯:獲得必要的特權
您需要SE_TIME_ZONE_NAME
特權(見here)。有一個方便實施更改權限,AdjustPrivilege
over here。
全部放在一起:
import ntsecuritycon, win32security, win32api
def AdjustPrivilege(priv):
flags = ntsecuritycon.TOKEN_ADJUST_PRIVILEGES | ntsecuritycon.TOKEN_QUERY
htoken = win32security.OpenProcessToken(win32api.GetCurrentProcess(), flags)
id = win32security.LookupPrivilegeValue(None, priv)
newPrivileges = [(id, ntsecuritycon.SE_PRIVILEGE_ENABLED)]
win32security.AdjustTokenPrivileges(htoken, 0, newPrivileges)
# Enable the privilege
AdjustPrivilege(win32security.SE_TIME_ZONE_NAME)
# Set the timezone
win32api.SetTimeZoneInformation((-600,u'Eastern Standard Time',(2000,4,1,3,0,0,0,0),0,u'Eastern Daylight Time',(2000,10,1,2,0,0,0,0),-60))
@unice讓我知道,如果它的工作對你 – pandita
很抱歉這麼晚纔回復。謝謝@pandita,它的工作原理。我可以用第二個參數修改當前的日期和時間嗎?因爲當我使用SetSystemTime更改日期/時間時,它會自動添加+8小時或根據時區。 – unice
@pandita如果我想將時區更改爲「歐洲/倫敦」,我該怎麼做?只需更換「東部標準時間」將不起作用。任何解釋?或者,那個論點的所有有效值是什麼? – swdev