+ 1
how to pull out year ,mon and day from this output using python?
time.struct_time(tm_year=2019, tm_mon=3, tm_mday=4, tm_hour=8, tm_min=31, tm_sec=42, tm_wday=0, tm_yday=63, tm_isdst=0) need output in integer format
2 Antworten
+ 2
By indexing!
Let's say your time object has been stored in x:
year = x[0]
mon = x[1]
day = x[2]
Or pythonic:
year, month, day = x[:3]
+ 1
It would be better and more Pythonic, to use the Datetime module
import datetime
x = datetime.datetime(2019,3,4,8,31,42)
year = x.year
mon = x.month
day = x.day
print(year)
print(mon)
print(day)