python - 日期时间格式转换

标签 python list datetime

我有这些的 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/

相关文章:

python - 为什么这个 linux 命令在使用 python 执行时不起作用?

pandas - 如何在pandas groupby之后获取列表列表

python - 如何检查坐标网格中是否存在坐标对(纬度,经度)?

Python:使用 `signal.alert` 超时 I/O 的缺点?

java - 对象被添加到列表中,但不与其他对象一起排序,而是添加到最后

c++ - 如何创建具有固定索引的 QList

python - 如何更改列中的日期?

c# - 如何格式化 DateTime 或 TimeZone/TimeZoneInfo 以显示三个字母?

c++ - 将 MySQL 日期时间转换为 C++ std::time_t

python - 按降序从数组中获取前 N 个元素