如何将python datetime.datetime转换为列表 [英] how to convert a python datetime.datetime into a list
本文介绍了如何将python datetime.datetime转换为列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个datetime.datetime对象。我要做的就是提取数据并将其放入列表中。我发现的唯一方法是:
I have a datetime.datetime object. All I want to do is pull it's data out and put it into a list. The only method I have found is:
date_list=list(my_dt_ob.timetuple())
这似乎是做一个概念上简单的事情的复杂方法。有人有更好的方法吗?谢谢。
This seems to be an awfully convoluted way of doing a conceptually simple thing. Anyone have a better way? Thanks.
推荐答案
日期和时间的每个部分都可以作为 datetime
对象。您可以直接使用它们:
Each of the parts of the date and time are available as attributes of the datetime
object. You can use them directly:
date_list = [my_dt_ob.year, my_dt_ob.month, my_dt_ob.day, my_dt_ob.hour, my_dt_ob.minute, my_dt_ob.second]
这篇关于如何将python datetime.datetime转换为列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文