基于添金的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)。有一个方便实施更改权限,AdjustPrivilegeover 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))