import datetime time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') print(time) # 结果 # 2019-07-31 19:08:17