Friday 15 July 2016

Python: time.mktime: Convert strut_time to local time


'time.mktime(t)' is used to convert struct_time to local time in seconds (returns a floating point number).
>>> import time
>>> now=time.localtime()
>>> now
time.struct_time(tm_year=2015, tm_mon=11, tm_mday=10, tm_hour=11, tm_min=9, tm_sec=51, tm_wday=1, tm_yday=314, tm_isdst=0)
>>> 
>>> 
>>> seconds=time.mktime(now)
>>> seconds
1447133991.0
>>> 
>>> time.localtime(1447133991.0)
time.struct_time(tm_year=2015, tm_mon=11, tm_mday=10, tm_hour=11, tm_min=9, tm_sec=51, tm_wday=1, tm_yday=314, tm_isdst=0)



Previous                                                 Next                                                 Home

No comments:

Post a Comment