python实现每天定时任务(2)

来源:互联网 发布:扩音软件 编辑:程序博客网 时间:2024/06/03 19:24

下面代码执行时是在当天的20点执行任务。

import timefrom datetime import datetime, timedeltafrom time import sleepSECONDS_PER_DAY = 24 * 60 * 60def doFunc():    print "do Function..."def doFirst():    curTime = datetime.now()    print curTime    desTime = curTime.replace(hour=20, minute=0, second=0, microsecond=0)    print desTime    delta = desTime-curTime    sleeptime = delta.total_seconds()    print "Now day must sleep %d seconds" %     sleeptime    sleep(sleeptime)    doFunc()if __name__ == "__main__":    doFirst()


0 0
原创粉丝点击