Skip to content Skip to sidebar Skip to footer

Converting Time.struct_time To List

In Python, how do I convert a time.struct_time such as time.struct_time(tm_year=2012, tm_mon=10, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=275, tm_isdst=-1) to

Solution 1:

Convert it with list(obj), ex:

>>> a = time.gmtime() >>> a time.struct_time(tm_year=2012, tm_mon=10, tm_mday=31, tm_hour=2, tm_min=53, tm_sec=4, tm_wday=2, tm_yday=305, tm_isdst=0) >>> list(a) [2012, 10, 31, 2, 53, 4, 2, 305, 0]

Solution 2:

Calling the list() constructor will do what you need:

>>>t = time.localtime()>>>list(t)
[2012, 10, 30, 22, 54, 25, 1, 304, 1]

Post a Comment for "Converting Time.struct_time To List"