python修改系统时间_python修改操作系统时间的方法

  • Post author:
  • Post category:python


本文实例讲述了python修改操作系统时间的方法。分享给大家供大家参考。具体实现方法如下:

#-*- coding:utf-8 -*-

import socket

import struct

import time

import win32api

TimeServer = ‘210.72.145.44’ #国家授时中心ip

Port = 123

def getTime():

TIME_1970 = 2208988800L

client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

data = ‘x1b’ + 47 * ‘ ‘

client.sendto(data, (TimeServer, Port))

data, address = client.recvfrom(1024)

data_result = struct.unpack(‘!12I’, data)[10] data_result -= TIME_1970

return data_result

def setSystemTime():

tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst = time.gmtime(getTime())

win32api.SetSystemTime(tm_year, tm_mon, tm_wday, tm_mday, tm_hour, tm_min, tm_sec, 0)

print “Set System OK!”

if



版权声明:本文为weixin_39619170原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。