How do I find the time difference between two datetime objects in python?

前端 未结 17 1335
無奈伤痛
無奈伤痛 2020-11-22 11:06

How do I tell the time difference in minutes between two datetime objects?

17条回答
  •  忘掉有多难
    2020-11-22 11:57

    Use divmod:

    now = int(time.time()) # epoch seconds
    then = now - 90000 # some time in the past
    
    d = divmod(now-then,86400)  # days
    h = divmod(d[1],3600)  # hours
    m = divmod(h[1],60)  # minutes
    s = m[1]  # seconds
    
    print '%d days, %d hours, %d minutes, %d seconds' % (d[0],h[0],m[0],s)
    

提交回复
热议问题