Calculating Time Difference

前端 未结 5 1994
情话喂你
情话喂你 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:27

    The datetime module will do all the work for you:

    >>> import datetime
    >>> a = datetime.datetime.now()
    >>> # ...wait a while...
    >>> b = datetime.datetime.now()
    >>> print(b-a)
    0:03:43.984000
    

    If you don't want to display the microseconds, just use (as gnibbler suggested):

    >>> a = datetime.datetime.now().replace(microsecond=0)
    >>> b = datetime.datetime.now().replace(microsecond=0)
    >>> print(b-a)
    0:03:43
    

提交回复
热议问题