我已经将两个日期视为
import datetime
data1 = datetime.datetime.now()
data2 = datetime.datetime.now()
我这样做了,我得到了分钟和秒钟。我也想要几个小时;我怎么能这样做?
我的代码:
diff = data2-data1
divmod(diff.days * 86400 + diff.seconds, 60)
(3, 45)
我怎么能得到好几个小时?任何帮助将不胜感激。
答案 0 :(得分:22)
终于找到了解决方案
import datetime
data1 = datetime.datetime.now()
data2 = datetime.datetime.now()
diff = data2 - data1
days, seconds = diff.days, diff.seconds
hours = days * 24 + seconds // 3600
minutes = (seconds % 3600) // 60
seconds = seconds % 60
print hours,minutes,seconds