python计算时间间隔

from datetime import datetime

if __name__ == '__main__':
    s = '2018-05-01 11:58:24.480819'
    s1 = '2018-05-02 09:13:33.145445'
    a = datetime.strptime(s, '%Y-%m-%d %H:%M:%S.%f')
    b = datetime.strptime(s1, '%Y-%m-%d %H:%M:%S.%f')
    print((b - a).total_seconds()) # 注意total_seconds()的seconds的区别

你可能感兴趣的:(python计算时间间隔)