Python datetime获取当前年月日时分秒
from datetime import datetime now_time = datetime.now() str_time = now_time.strftime("%Y-%m-%d %X")# 格式化时间字符串 print(str_time)
输出
2021-06-11 17:08:35
from datetime import datetime now_time = datetime.now() str_time = now_time.strftime("%Y-%m-%d %X")# 格式化时间字符串 print(str_time)
输出
2021-06-11 17:08:35