Calculating Time Difference

前端 未结 5 2022
情话喂你
情话喂你 2020-12-02 16:47

at the start and end of my program, I have

from time import strftime
print int(strftime(\"%Y-%m-%d %H:%M:%S\")



Y1=int(strftime(\"%Y\"))
m1=int(strftime(\         


        
5条回答
  •  星月不相逢
    2020-12-02 17:28

    You cannot calculate the differences separately ... what difference would that yield for 7:59 and 8:00 o'clock? Try

    import time
    time.time()
    

    which gives you the seconds since the start of the epoch.

    You can then get the intermediate time with something like

    timestamp1 = time.time()
    # Your code here
    timestamp2 = time.time()
    print "This took %.2f seconds" % (timestamp2 - timestamp1)
    

提交回复
热议问题