时区的变化不会反映在python的日期时间。现在()功能

2024-09-29 00:22:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在用这个代码在我的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()

Tags: thetokeniddatetime时间nowflagsse