首页 > 代码库 > 时间转时间戳例子

时间转时间戳例子

#!/usr/bin/python

import time

import os



if __name__ == ‘__main__‘:

    hwclock_time = " ".join(os.popen("hwclock --show --utc").read().split(" ")[0:6])

    hwclock_timestamp = time.mktime(time.strptime(hwclock_time,‘%a %d %b %Y %I:%M:%S %p‘))

    os_time = time.time()

    difference = abs(int(hwclock_timestamp)-int(os_time))

    if difference > 60: 

        print ‘difference:‘,difference

        exit(1)

    else:

        print ‘time is correct‘