#!/usr/bin/python
#!_*_coding:utf-8_*_
import os
#import datetime
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
print Value
#正确的时间戳
TimeStamp = int(os.popen(‘date +%s‘).read()) + Value
print TimeStamp
#DateArry = datetime.datetime.utcfromtimestamp(TimeStamp)
#NewSysTime = DateArry.strftime("%Y-%m-%d %H:%M:%S")
Date = time.localtime(TimeStamp)
NewSysTime = time.strftime("%Y-%m-%d %H:%M:%S",Date)
print NewSysTime原文:http://ahaii.blog.51cto.com/1695127/1653994