python循环增加系统时间

代码的作用是按照对应的循环次数,每次给当前系统时间加上5秒。

import time
import datetime
import os
for num in range(1,50):
    aftertime = (datetime.datetime.now() + datetime.timedelta(seconds=5)).strftime("%Y-%m-%d %H:%M:%S")
    print('5S后时间:%s' % (aftertime))
    os.system('date -s "%s"' % (aftertime))
    print('这是第%s次循环' % (num))
    time.sleep(3600)

推荐python3运行。

本文为原创文章,转载请注明出处。

原文链接:https://850406.xyz/post/python循环增加系统时间

评论(0)

还没有评论,来抢沙发吧~

验证码