Example:
1 #-*-coding=utf-8-*-2 __author__='Zhongtang'3 4 5 Import Time6strtime1='20160518010101'7Strtime2='20160518020101'8 9 #string becomes time data structureTenLocaltime1=time.strptime (Strtime1,'%y%m%d%h%m%s') OneLocaltime2=time.strptime (Strtime2,'%y%m%d%h%m%s') A - Printtype (localtime1), localtime1 - Printtype (localtime2), localtime2 the - - #convert from time data structure to timestamp -time1=time.mktime (localtime1) +Time2=time.mktime (localtime2) - + Printtype (time1), time1 A Printtype (time2), time2 at - #Timestamps can be subtracted directly to get the difference in seconds - PrintTime2-time1
Output results
1<type'Time.struct_time'> Time.struct_time (tm_year=2016, tm_mon=5, tm_mday=18, Tm_hour=1, Tm_min=1, Tm_sec=1, tm_wday=2, tm_yday=139, tm_ Isdst=-1)2<type'Time.struct_time'> Time.struct_time (tm_year=2016, tm_mon=5, tm_mday=18, tm_hour=2, Tm_min=1, Tm_sec=1, tm_wday=2, tm_yday=139, tm_ Isdst=-1)3<type'float'> 1463504461.04<type'float'> 1463508061.053600.0
String format time comparison under Python