*获取当前时间
可以使用datatime和time模块,如下两种情况结果是一样的
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
now2 = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
# 2019-12-26 09:40:58
# 2019-12-26 09:40:58
*获取一秒,一分钟,一天前的时间
print((datetime.datetime.now() - datetime.timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S"))
print((datetime.datetime.now() - datetime.timedelta(minutes=1)).strftime("%Y-%m-%d %H:%M:%S"))
print((datetime.datetime.now() - datetime.timedelta(seconds=1)).strftime("%Y-%m-%d %H:%M:%S"))
# 2019-12-25 09:43:20
# 2019-12-26 09:42:20
# 2019-12-26 09:43:19