Reputation: 179
I came across this question: Converting time.struct_time to list and am wondering is there a way to go backwards, convert a list to time.struct_time.
[2012, 10, 1, 0, 0, 0, 0, 275, -1]
to this
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)
Upvotes: 1
Views: 905
Reputation: 1228
You can just convert it like below
l= [2012, 10, 1, 0, 0, 0, 0, 275, -1]
import time
s = time.struct_time(l)
Init signature: time.struct_time(iterable=(), /) Docstring:
The time value as returned by gmtime(), localtime(), and strptime(), and accepted by asctime(), mktime() and strftime(). May be considered as a sequence of 9 integers.
Note that several fields' values are not the same as those defined by the C language standard for struct tm. For example, the value of the field tm_year is the actual year, not year - 1900. See individual fields' descriptions for details.
Type: type
Subclasses:
Upvotes: 6