how to convert a python datetime.datetime into a list

后端 未结 1 1841
抹茶落季
抹茶落季 2021-01-06 20:21

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         


        
相关标签:
1条回答
  • 2021-01-06 20:38

    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]
    
    0 讨论(0)
提交回复
热议问题