Python 时间转化

1、字符串转datetime

from datetime import datetime, timedelta
time_a = datetime.strptime('2022-09-03 20:31:10', "%Y-%m-%d %H:%M:%S")


2、datetime转字符串

str_time_a = time_a.strftime("%Y-%m-%d")

  输出

2022-09-03 20:31:10
2022-09-03

 

posted on 2022-09-30 17:44  滚动的蛋  阅读(30)  评论(0编辑  收藏  举报

导航