+ 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

4th Mar 2019, 10:08 AM
Raj Charan
2 Réponses
+ 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]
4th Mar 2019, 10:40 AM
HonFu
HonFu - avatar
+ 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)
9th Mar 2019, 5:18 PM
Barry Andersen