Friday 15 July 2016

Python: time.strptime: Convert string to stuct_time value

In previous post, I explained how to convert time value to a string. In this post i am going to explain how to convert formatted string to a struct_time value. ‘time.strptime(string[, format])’ function is used to convert a formatted string to decimal value.

>>> import time
>>> print(time.strptime("15/11/10 10:34","%y/%m/%d %H:%M"))
time.struct_time(tm_year=2015, tm_mon=11, tm_mday=10, tm_hour=10, tm_min=34, tm_sec=0, tm_wday=1, tm_yday=314, tm_isdst=-1)
>>> 
>>> print(time.strptime("2015/11/10 10:34:03","%Y/%m/%d %H:%M:%S"))
time.struct_time(tm_year=2015, tm_mon=11, tm_mday=10, tm_hour=10, tm_min=34, tm_sec=3, tm_wday=1, tm_yday=314, tm_isdst=-1)


Previous                                                 Next                                                 Home

No comments:

Post a Comment