python修改操作系统时间的方法,python修改操作系统
python修改操作系统时间的方法,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 * '\0' 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 __name__ == '__main__': setSystemTime() print "%d-%d-%d %d:%d:%d" % time.localtime(getTime())[:6]
希望本文所述对大家的Python程序设计有所帮助。
相关内容
- 解读Python中degrees()方法的使用,pythondegrees
- Python Matplotlib库入门指南,matplotlib入门指南
- Python中转换角度为弧度的radians()方法,pythonradians
- Python NumPy库安装使用笔记,pythonnumpy
- 浅析Python中将单词首字母大写的capitalize()方法,python
- Python中Random和Math模块学习笔记,pythonrandom
- 简介Python中用于处理字符串的center()方法,pythoncenter
- 收藏整理的一些Python常用方法和技巧,整理python技巧
- Python字符串处理之count()方法的使用,pythoncount
- Python虚拟环境Virtualenv使用教程,pythonvirtualenv
评论关闭