python 计算时间差 字符串
1 #coding:utf8 2 import datetime 3 def time_differ(date1='12:55:05',date2='13:15:05'): 4 ''' 5 @传入是时间格式如'12:55:05' 6 ''' 7 date1=datetime.datetime.strptime(date1,"%H:%M:%S") 8 date2=datetime.datetime.strptime(date2,"%H:%M:%S") 9 if date1 < date2: 10 return date2-date1 11 else: 12 return date1-date2 13 14 date1 = '13:05:05' 15 date2 = '13:15:05' 16 differ = time_differ(date1,date2) 17 18 print differ