我的日期格式为codecov
,我需要将其转换为mm/dd/yyyy
yyyy/mm/dd
答案 0 :(得分:1)
您可以这样做。
from datetime import datetime
published_dateformat = "7/11/2019 at 7.09pm"
published_date = (published_dateformat).split('at')[0][:-1]
print(datetime.strptime(published_date,'%d/%m/%Y').strftime("%Y/%m/%d"))
答案 1 :(得分:0)
尝试一下:
from datetime import datetime
published_dateformat = "7/11/2019 at 7.09pm"
published_date = published_date = (published_dateformat).split('at')[0][:-1]
published_date = datetime.strptime(published_date,"%d/%m/%Y")
new_published_date = published_date.strftime("%Y/%m/%d")
这样,new_published_date
的值为'2019/11/07'