How do I find the time difference between two datetime objects in python?
问题 How do I tell the time difference in minutes between two datetime objects? 回答1: >>> import datetime >>> a = datetime.datetime.now() >>> b = datetime.datetime.now() >>> c = b - a datetime.timedelta(0, 8, 562000) >>> divmod(c.days * 86400 + c.seconds, 60) (0, 8) # 0 minutes, 8 seconds 回答2: New at Python 2.7 is the timedelta instance method .total_seconds() . From the Python docs, this is equivalent to (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 . Reference: http:/