#!/usr/bin/python #!_*_coding:utf-8_*_ import os import time #获取文件在系统的时间戳 SysTime = int(os.popen("stat -t /home/ftp/sync.log | awk '{print $12}'").read()) #读取文件内记录的时间戳 WinTime = int(open('/home/ftp/sync.log','r').read()) if SysTime == WinTime: pass else: #时间戳差值 Value = WinTime - SysTime #正确的时间戳 TimeStamp = int(os.popen('date +%s').read()) + Value #将正常的时间戳转换成标准时间格式NewSysTime Date = time.localtime(TimeStamp) NewSysTime = time.strftime("%Y-%m-%d %H:%M:%S",Date) #修改系统时间 os.system(("date -s " + "'" + "%s" %NewSysTime + "'"))