更改时区不会反映在python的datetime.now()函数中

时间:2015-03-12 02:41:28

标签: python windows datetime timezone

我一直在使用此代码来更改Windows操作系统中的时区。它工作正常,但是当我通过datetime.now()获得新的日期和时间时,它会给出我仍未更改的日期和时间。我必须为它重新运行脚本以获得正确的日期和时间。谢谢

def adjustPrivilege( priv ):
    try:
        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)
    except:
        pass
# Enable the privilege
adjustPrivilege(win32security.SE_TIME_ZONE_NAME)

# Set the timezone
win32api.SetTimeZoneInformation((-480,u'China Standard Time',(2000,0,0,0,0,0,0,0),0,u'China Standard Time',(2000,0,0,0,0,0,0,0),-0))
time.sleep(5)
print datetime.datetime.now()

0 个答案:

没有答案