首页 > 代码库 > python 计算时间差 字符串

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-date111     else:12         return date1-date213 14 date1 = 13:05:0515 date2 = 13:15:0516 differ = time_differ(date1,date2)17 18 print differ

 

python 计算时间差 字符串