How to parse time in Python

1 Answer

0 votes
import time  

def print_time_struct(ts):         
    print('tm_year:', ts.tm_year)         
    print('tm_mon:', ts.tm_mon)         
    print('tm_mday:', ts.tm_mday)         
    print('tm_hour:', ts.tm_hour)         
    print('tm_min:', ts.tm_min)         
    print('tm_sec:', ts.tm_sec)         
    print('tm_wday:', ts.tm_wday)         
    print('tm_yday:', ts.tm_yday)         
    print('tm_isdst:', ts.tm_isdst)



spt = time.strptime(time.ctime())     
   
print_time_struct(spt)



'''
run:

tm_year: 2019
tm_mon: 6
tm_mday: 3
tm_hour: 15
tm_min: 29
tm_sec: 16
tm_wday: 0
tm_yday: 154
tm_isdst: -1

'''

 



answered Jun 3, 2019 by avibootz
...