1、python 打印时间

import time 

print('my name:%s'%time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) 
print('my name2:%s'%time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()))

from time import strftime, localtime

# 打印当前时间
def printTime():

    print(strftime("%Y-%m-%d %H:%M:%S", localtime()))

    return

2、程序运行时间

import time 
import datetime

#print('my name:%s'%time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) 
#print('my name2:%s'%time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()))

def run_fun(num):

    i=0
    cycle = 10000000*num
    while i<cycle:
          i+=1
    print("run process")


starttime = datetime.datetime.now()
run_fun(5)
endtime = datetime.datetime.now()
seconds  = (endtime - starttime).seconds
print seconds

m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
print("%d:%02d:%02d" % (h, m, s))



start = time.time()
run_fun(5)
end = time.time()

seconds = end-start
print seconds
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
print("%d:%02d:%02d" % (h, m, s))

start = time.clock()
run_fun(5)
end = time.clock()

seconds = end-start
print seconds

m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
print("%d:%02d:%02d" % (h, m, s))

https://edu.csdn.net/topic/python115?utm_source=blogt3two

相关文章:

  • 2021-12-05
  • 2021-02-26
  • 2021-10-19
  • 2019-12-02
  • 2021-12-05
  • 2021-12-05
  • 2021-11-04
猜你喜欢
  • 2018-05-09
  • 2021-10-07
  • 2021-08-31
  • 2019-12-25
  • 2021-11-21
  • 2021-12-05
  • 2021-09-14
相关资源
相似解决方案