Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我一直在试图弄清楚如何在两个时间字段之间进行简单的减法运算,并在管理页面上显示总时间以及在保存之前进行确认。例如实际到达时间 - 实际出发时间 = 总飞行时间
atd = models.TimeField(null=True, default='00:00:00') ata = models.TimeField(null=True, default='00:00:00')
试图让 atd - ata 获得总飞行时间,我如何在 django 中做到这一点。
感谢您的帮助!
您可以尝试以下方法
import datetime time1 = datetime.datetime.strptime(atd,'%H:%M:%S') time2 = datetime.datetime.strptime(ata,'%H:%M:%S') difference = time2-time1