当我遇到关于python的datetime和timedelta实例的另一个线程时,这个问题就产生了
我按照更新jimgardener并阅读评论eyquem,并尝试了一些python代码..我很难理解这里的工作方式(由于我的新手到python状态)..我认为这是正确的问一个新问题
import datetime
#for t1=23:30:00 PM
t1 = datetime.time(23,30,00)
#for t1=00:15:30 AM
t2 = datetime.time(0,15,30)
td1 = datetime.timedelta(hours=t1.hour,minutes = t1.minute,seconds=t1.second)
td2 = datetime.timedelta(hours=t2.hour,minutes = t2.minute,seconds=t2.second)
#substarcting timedeltas
tdiff = td2-td1
Run Code Online (Sandbox Code Playgroud)
打印出这些变量
td1 ==> datetime.timedelta(0, 84600)
td1.seconds ==> 84600
td2 ==> datetime.timedelta(0, 930)
td2.seconds ==> 930
tdiff ==> datetime.timedelta(-1, 2730)
Run Code Online (Sandbox Code Playgroud)
当我看到这些结果时,我注意到了
td1.seconds (ie 84600) is equivalent to
84600/60 ==> 1410 minutes
1410/60 ==> 23.5 hours
or in short,td1 represents the duration **from previous midnight** …Run Code Online (Sandbox Code Playgroud)