根据Python module to change system date and time-我们可以使用此代码更改系统时间。我已经调整了这段代码并相应地进行了更改,但是执行脚本会将时间更改为UTC格式,但大约10秒后会更新到正确的时间。这种无法解释的行为促使我改为使用SetLocalTime方法。但是,我不能让这个工作。在import socket
import struct
import sys
import time
import win32api
TIME1970 = 2208988800
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
data = '\x1b' + 47 * '\0'
client.sendto(data.encode(), ('10.0.0.1', 123))
data, address = client.recvfrom(1024)
if data:
print('Response received from:', address)
t = struct.unpack('!12I', data)[10]
t -= TIME1970
tf = time.strptime(time.ctime(t))
time_tuple = (tf[0], # Year
tf[1], # Month
tf[6], # Day of Week
tf[2], # Day
tf[3], # Hour
tf[4], # Minute
tf[5], # Second
0,#int(round(tf[5] * 1000)), # Millisecond
)
print(tf)
win32api.SetLocalTime(*time_tuple)
返回时返回错误TypeError: SetLocalTime() takes exactly 1 argument (8 given)。我知道SetLocalTime函数采用与SetSystemTime完全相同的参数,但事实并非如此。在
我在谷歌上找不到任何地方有任何例子,所以我无法完成我的代码。在
如有任何建议,我们将不胜感激。谢谢您。在