Date difference in minutes in Python

后端 未结 11 1368
谎友^
谎友^ 2020-11-28 23:03

How do I calculate the difference in time in minutes for the following timestamp in Python?

2010-01-01 17:31:22
2010-01-03 17:31:22
11条回答
  •  攒了一身酷
    2020-11-28 23:34

    from datetime import datetime
    
    fmt = '%Y-%m-%d %H:%M:%S'
    d1 = datetime.strptime('2010-01-01 17:31:22', fmt)
    d2 = datetime.strptime('2010-01-03 17:31:22', fmt)
    
    print (d2-d1).days * 24 * 60
    

提交回复
热议问题