一 概念
datetime的用法如下:
二 源码解析
import time import datetime def sleeptime(hour,min,sec): return 3600*hour + 60*min + sec def test(): seconds = sleeptime(0,0,5) while True: time.sleep(seconds) print("first wake up do some time is:",datetime.datetime.now().strftime("%Y:%m:%d %H:%M:%S")) time.sleep(seconds) print("second wake up do some time is:",datetime.datetime.now().strftime("%Y:%m:%d %H:%M:%S")) if __name__=='__main__': test()
三 总结
time的用处特别大,熟练掌握是基本。