import datetime
mylist = []
today = datetime.date.today()
mylist.append(today)
print mylist
Result: [datetime.date (2016, 1, 20)]
The result I want is 2016-1-20.
When you print out the date
format right away, it comes out as "2016-1-20"
I put it on the list and print it out, so it looks weird.
Is the only way to print all the elements like "2016-1-20" the only way to turn it around?
datetime date python
When you print it out right away, you get the result you want
I thought there was a high possibility that either of these results would be the desired result.
Actually, str(today)
is the same format you mentioned in the question. Therefore, when you put the date, you can put str(today)
or simply
print map(str, mylist)
I think you can do it like this.
© 2024 OneMinuteCode. All rights reserved.