问题
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