python计算时间间隔

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/x18835129278/article/details/89955801
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的区别

猜你喜欢

转载自blog.csdn.net/x18835129278/article/details/89955801
今日推荐