日期时间格式转换 [英] Date Time Format Conversion
本文介绍了日期时间格式转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这些列表;
datetime.datetime(2011, 1, 31, 19, 30)
我想创建一个这些列表;
I wish to create a list of these;
2011-01-31 17:30:00
这是在一个循环中完成的吗?
How is this done in a loop?
推荐答案
对于 datetime
和 date
实例 str
返回ISO日期:
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
方法直接:
You can also call isoformat
method directly:
In [17]: [d.isoformat(sep=' ') for d in dates]
Out[17]:
['2011-01-31 19:30:00']
这篇关于日期时间格式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文