37,718
社区成员
发帖
与我相关
我的任务
分享
def x(a, b):
al = a.split('.')
bl = b.split('.')
stt = lambda t: time.mktime(time.strptime(t, "%Y-%m-%d %H:%M:%S"))
print stt(al[0]) - stt(bl[0]) + (int(al[1]) - int(bl[1])) / 1000000.0
仔细看了下 还有更简洁的 python2
print (datetime.datetime.strptime('2015-02-02 00:00:41.986268', "%Y-%m-%d %H:%M:%S.%f") - datetime.datetime.strptime('2014-02-01 00:00:41.886267', "%Y-%m-%d %H:%M:%S.%f")).total_seconds()
import datetime
dt1 = datetime.datetime.strptime(date1, "%Y-%m-%d %H:%M:%S.%f")
dt2 = datetime.datetime.strptime(date2, "%Y-%m-%d %H:%M:%S.%f")
d = dt2 - dt1