如何以常规格式打印日期?

ε祈祈猫儿з 提交于 2020-08-08 00:54:54

问题:

This is my code: 这是我的代码:

import datetime
today = datetime.date.today()
print today

This prints: 2008-11-22 which is exactly what I want. 打印: 2008-11-22这正是我想要的。

But, I have a list I'm appending this to and then suddenly everything goes "wonky". 但是,我有一个列表要附加到该列表中,然后突然所有内容都变得“异常”。 Here is the code: 这是代码:

import datetime
mylist = []
today = datetime.date.today()
mylist.append(today)
print mylist

This prints the following: 打印以下内容:

[datetime.date(2008, 11, 22)]

How can I get just a simple date like 2008-11-22 ? 我怎样才能得到像2008-11-22这样的简单约会?


解决方案:

参考一: https://stackoom.com/question/1J4F/如何以常规格式打印日期
参考二: https://oldbug.net/q/1J4F/How-to-print-a-date-in-a-regular-format
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!