python 日期时间计算、日期时间相减、日期时间间隔

import datetime


def timeInterval(time1,time2):
    """
    time1-time2
    """
    dt1=datetime.datetime.strptime(time1,'%Y-%m-%d %H:%M:%S')
    dt2=datetime.datetime.strptime(time2,'%Y-%m-%d %H:%M:%S')

    d=dt1-dt2
    snd=d.total_seconds()
    return snd

if __name__=="__main__":
    res=timeInterval("2018-01-03 11:23:18","2018-01-03 11:23:08")
    print(res)

原文出处:/show_1IX1fdv0hS6f.html