我有这些的 list ;
datetime.datetime(2011, 1, 31, 19, 30)
我想创建一个列表;
2011-01-31 17:30:00
这是如何在循环中完成的?
最佳答案
For datetime
and date
instances str
returns ISO dates :
In [15]: dates = [datetime(2011, 1, 31, 19, 30)]
In [16]: [str(d) for d in dates]
Out[16]:
['2011-01-31 19:30:00']
您也可以调用isoformat
直接方法:
In [17]: [d.isoformat(sep=' ') for d in dates]
Out[17]:
['2011-01-31 19:30:00']
关于python - 日期时间格式转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25043190/