CPU占用过高可以使用time.sleep(x)休眠
#coding=utf-8
import time
def checkTime(s):
____stp = time.mktime(time.strptime(s, '%Y-%m-%d %H:%M:%S'))
____while True:
________if time.time() - stp > 0:
____________break
________time.sleep(1)
s = '2016-10-23 20:40:30'
checkTime(s)
print('okay')
/******************************************/
import time
时间戳
>>> time.time()
1477225245.837485
结构时间?
>>> time.localtime()
time.struct_time(tm_year=2016, tm_mon=10, tm_mday=23, tm_hour=20, tm_min=20, tm_sec=50, tm_wday=6, tm_yday=297, tm_isdst=0)
根据结构时间或者时间元组获取时间戳
>>> time.mktime(time.localtime())
1477225265.0
可以不用设置完整的元组,但是必须是9个元素
>>> time.mktime((2016,10,23,20,21,0,0,0,0))
1477225260.0
根据时间戳获取元组/结构
>>> time.gmtime(time.time())
time.struct_time(tm_year=2016, tm_mon=10, tm_mday=23, tm_hour=12, tm_min=21, tm_sec=39, tm_wday=6, tm_yday=297, tm_isdst=0)
根据时间字符串获取时间戳
>>> time.strptime('2016-3-4', '%Y-%m-%d')
time.struct_time(tm_year=2016, tm_mon=3, tm_mday=4, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=4, tm_yday=64, tm_isdst=-1)