Convert a list of DateTime objects to string in python [duplicate]

一个人想着一个人 提交于 2020-06-01 07:13:05

问题


I have a list of Dates returning Mondays between two dates

mondays =[datetime.date(2019, 2, 14), datetime.date(2019, 2, 21)]

How do I format this list to %Y%m%d format?

Expecting output list to be in the below format:

['20190214','20190221']

is there a way?


回答1:


the following will work

[date_obj.strftime('%Y%m%d') for date_obj in mondays]

Output

['20190214', '20190221']


来源:https://stackoverflow.com/questions/54527912/convert-a-list-of-datetime-objects-to-string-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!